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 |
dasu
Posting Yak Master
104 Posts |
Posted - 2004-08-17 : 02:40:53
|
when iam tryin gto execute stored procedure iam gettin error like undeclare cnt variableplease see the code following and suggest me solutionthanks in advance"alter proc das_ee @tn varchar(40)asdeclare @cnt varchar(30), @q varchar(400)set @q='select @cnt= count(*) from '+ @tnexec (@q)--print (@cnt)exec das_ee 'test'" |
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-08-17 : 03:06:26
|
The exec statement is its own batch and variables exist only in the batch in which they were declared.This should do what you want:[CODE]alter proc das_ee @tn varchar(40)asdeclare@cnt varchar(30),@q varchar(400)create table #cnt(cnt int)set @q='insert into #cnt select count(*) from '+ @tnexec (@q)set @cnt = (select cnt from #cnt)drop table #cnt--print (@cnt)[/CODE]Duane. |
|
|
samsekar
Constraint Violating Yak Guru
437 Posts |
|
|
|
|