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 |
|
nice123ej
Starting Member
48 Posts |
Posted - 2007-07-07 : 01:47:47
|
| I want to get a singular result from EXEC functionexample-------------------------------------------declare @sqlscript varchar(1000)declare @i intset @sqlscript = 'select count(*) from mytable'set @i = exec(sqlscript)-------------------------------------------i know this script wont work but how can i get the count result in @ii know i can use select @i= count(*) from mytablebut this is not what i want @sqlscript is variable and can be anythingcan anyone help?! |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
bpgupta
Yak Posting Veteran
75 Posts |
Posted - 2007-07-07 : 03:21:30
|
| you can rewrite declare @sqlscript varchar(1000)declare @i intselect @i = count(*) from mytableselect @i |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-07 : 03:27:21
|
That is not what OP wantsquote: i know i can use select @i= count(*) from mytablebut this is not what i want @sqlscript is variable and can be anything
KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-07-07 : 04:08:59
|
| or read about sp_executesql in sql server help fileMadhivananFailing to plan is Planning to fail |
 |
|
|
nice123ej
Starting Member
48 Posts |
Posted - 2007-07-07 : 11:56:50
|
| thx sp_executesql helped |
 |
|
|
|
|
|