Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Executing a variable

Author  Topic 

susan_151615
Yak Posting Veteran

99 Posts

Posted - 2009-01-08 : 05:19:31
Hi i want to assign a delete query to variable and i have to execute it.and i have done it like this inside the SP:


declare @vTrun varchar(128)
set @vTRUN="DELETE FROM UST_SAMP_DETAILS"
exec @vTRUN


The SP is been compiled successfully but while executing

it taking the statement "set @vTRUN="DELETE FROM UST_SAMP_DETAILS"
exec @vTRUN" as an SP and its throwing an error stating:

Could not find stored procedure 'DELETE FROM UST_SAMP_DETAILS'.


So can anyone tell me how to execute a variable to which i assign a delete query statement

susan

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-01-08 : 05:24:35
you could simply put
DELETE FROM UST_SAMP_DETAILS
, Why make it dynamic?

Incase you are just trying to test something, you could alter it to

declare @vTrun varchar(128)
set @vTRUN='DELETE FROM UST_SAMP_DETAILS'
exec (@vTRUN)
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2009-01-08 : 05:30:38
to answer the original question:

You have to use

EXEC (@vTRUN)


note the brackets


However, sakets makes a valid point -- why do this?
Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

susan_151615
Yak Posting Veteran

99 Posts

Posted - 2009-01-08 : 05:51:02
Hi thank u so much to both of you .Its working fine now

susan
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-08 : 08:30:05
quote:
Originally posted by susan_151615

Hi thank u so much to both of you .Its working fine now

susan


you still didnt answer the question asked..whats the purpose?
Go to Top of Page
   

- Advertisement -