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.
Author |
Topic |
itmasterw
Yak Posting Veteran
90 Posts |
Posted - 2013-04-11 : 13:50:55
|
Hi,I have an dynamic sql statement that rturns a percentage which works grate. However, I want to take this value and assign it to a variable. somthing like:Set @sql = 'Select....From Table'EXEC @sql@hold = value of the ececution above EXEC @sqlHow can I do this?Thank youITM |
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2013-04-11 : 14:16:02
|
well you cannot assign it to a variable, but instead you can assign it to a table .. declare @sql varchar(1000);declare @x table (col1 int);set @sql='SELECT 1;'insert into @xExec (@sql)select * from @xCheersMIK |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2013-04-11 : 14:16:29
|
Tyy using SP_EXECUTESQL.For Example:-- Assuming the datatype is VARCAHR(100)DECLARE @A VARCHAR(100)EXEC SP_EXECUTESQL N'SELECT @A = Column ... FROM TABLE', N'@A VARCHAR(100) OUTPUT', @A OUTPUTPRINT @A |
|
|
itmasterw
Yak Posting Veteran
90 Posts |
Posted - 2013-04-11 : 14:31:38
|
Okay thanks guys, I will try these.Thank youITM |
|
|
|
|
|