Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Execute Immediate syntax..

Posted on 2006-11-07
6
Medium Priority
?
919 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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
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…
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…
Suggested Courses

604 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