?
Solved

Execute Immediate syntax..

Posted on 2006-11-07
6
Medium Priority
?
917 Views
Last Modified: 2007-12-19
Hi,

Hope to get the solution for the below from expert asap..

SET @query = @query + ' FROM DBO.' + @sTable + ' WHERE ' + @sTable +'.ComponentId = '    + CONVERT(CHAR, @id);

EXECUTE IMMEDIATE @query;

Whats wrong with the above syntax, which i am trying to implement inside my cursor. I am getting error as:

Cannot add rows to sysdepends for the current stored procedure because it depends on the missing object 'IMMEDIATE'. The stored procedure will still be created.

Awaiting to hear your support on this asap.

Thanks in advance.
~ HNS ~
0
Comment
Question by:homnath_sharma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 total points
ID: 17895768
I assume you are using SQL server:
EXEC(@query);
0
 
LVL 5

Expert Comment

by:MrNetic
ID: 17898637
Remove the IMMEDIATE and run

EXEC @Variable.

Best Regards,

Paulo Condeça.
0
 
LVL 27

Expert Comment

by:Zberteoc
ID: 17899116
EXECUTE IMMEDIATE is a statement used in C language. In MS_SQL you hane EXECUTE or EXEC and you can also use the sp_executesql stored procedure, so either

EXEC(@query)   (you have to use brackets)

or

EXEC sp_executesql @query  (barackets are not required)

using sp_executesql gives you the advantage that you can pas into the @query parameters and also you cna use OUT parameters to get data from the execution.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question