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
 Development Tools
 Other Development Tools
 please suggest solution for this

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 variable
please see the code following and suggest me solution
thanks in advance
"

alter proc das_ee @tn varchar(40)
as
declare
@cnt varchar(30),
@q varchar(400)
set @q='select @cnt= count(*) from '+ @tn
exec (@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)
as
declare
@cnt varchar(30),
@q varchar(400)
create table #cnt(cnt int)
set @q='insert into #cnt select count(*) from '+ @tn
exec (@q)
set @cnt = (select cnt from #cnt)
drop table #cnt

--print (@cnt)
[/CODE]

Duane.
Go to Top of Page

samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2004-08-17 : 06:47:56
Check this!!
http://www.nigelrivett.net/sp_executeSQL.html

- Sekar
Go to Top of Page
   

- Advertisement -