|
-
Nov 7th, 2005, 04:44 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Dynmaic SQL Help.
Hey Guys,
I've done this a zillion times but beingMonday its way over my poor head ....
I want to set a variable from an exec of a dynamic SQL but the syntax is wobbly.
Like below (just for explanation)
Code:
DECLARE @C Char(20)
DECLARE @SQL Char(200)
Set @SQL = 'Select Top 1(Name) from tbl_Addr'
Set @C = Exec(@SQL)
Done it before but can't remember how...
Thanks
Chubby..
-
Nov 7th, 2005, 01:50 PM
#2
Re: Dynmaic SQL Help.
You cannot return a value when executing a dynamic t-sql statement, nor can you access the results of the statement unless they are placed in a global temporary table.
Perhaps you are thinking of the syntax of the Exec command to get the return value from a stored procedure.
Declare @C int
Exec @C = usp_SomeStoredProcedure
-
Nov 8th, 2005, 03:47 AM
#3
Thread Starter
Hyperactive Member
[resolved] Re: Dynamic SQL Help.
 Originally Posted by brucevde
You cannot return a value when executing a dynamic t-sql statement, nor can you access the results of the statement unless they are placed in a global temporary table.
Perhaps you are thinking of the syntax of the Exec command to get the return value from a stored procedure.
Declare @C int
Exec @C = usp_SomeStoredProcedure
ahh Bruce, Thanks for the reply. You can return the results to a variable (or variables), I remembered how I didi it. You use sp_executeSQL...
Cheers
Chubby..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|