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
 Need help in dtored procedures

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)
begin
set @sql = 'select count(*) from Emp'
set @var = exec(@sql)
print @var
end

while I execute the above code, am getting error near keyword exec

anyone solve this

Thanks in Advance

Suresh Kumar

sridhar.dbe
Starting Member

34 Posts

Posted - 2009-04-02 : 07:01:45
declare @sql nvarchar(2000)
begin
set @sql = 'select count(*) from Emp'
exec(@sql)
end

isk
Go to Top of Page

soori457
Yak Posting Veteran

85 Posts

Posted - 2009-04-02 : 07:05:33
Hai Sridhar, thanks for ur reply

Actually I need to set the output came from exec(@sql) to @var variable

plz solve this

Suresh Kumar
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-04-02 : 07:49:08
u can write like this soori,
declare @cnt int
select @cnt = count(*) from Emp
select @cnt
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-02 : 08:20:22
quote:
Originally posted by soori457

Hai Sridhar, thanks for ur reply

Actually I need to set the output came from exec(@sql) to @var variable

plz solve this

Suresh Kumar


Read about sp_executesql in sql server help file


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -