Solved

Execute Immediate syntax..

Posted on 2006-11-07
6
915 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 50 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 26

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Read about achieving the basic levels of HRIS security in the workplace.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

733 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