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 |
|
soori457
Yak Posting Veteran
85 Posts |
Posted - 2009-04-02 : 06:53:36
|
| Hai Everyone,declare @sql nvarchar(2000) declare @var varchar(200)beginset @sql = 'select count(*) from Emp'set @var = exec(@sql)print @varendwhile I execute the above code, am getting error near keyword execanyone solve this Thanks in AdvanceSuresh Kumar |
|
|
sridhar.dbe
Starting Member
34 Posts |
Posted - 2009-04-02 : 07:01:45
|
| declare @sql nvarchar(2000) beginset @sql = 'select count(*) from Emp'exec(@sql)endisk |
 |
|
|
soori457
Yak Posting Veteran
85 Posts |
Posted - 2009-04-02 : 07:05:33
|
| Hai Sridhar, thanks for ur replyActually I need to set the output came from exec(@sql) to @var variableplz solve thisSuresh Kumar |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-04-02 : 07:49:08
|
| u can write like this soori,declare @cnt intselect @cnt = count(*) from Empselect @cnt |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-02 : 08:20:22
|
quote: Originally posted by soori457 Hai Sridhar, thanks for ur replyActually I need to set the output came from exec(@sql) to @var variableplz solve thisSuresh Kumar
Read about sp_executesql in sql server help fileMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|