I have a stored procedure that uses an exec statement.
I use the exec statement because I want to
get info from a table
which is known through a parameter.
for example I have:
/* begin SQL */
create [sp]
@tablename varchar(50)
AS
exec ('
declare @err int
set @err =
(select count(*) from '+@tablename+' where a=1)
')
But I want to be able to return @err. Unfortunately
I can;t seem to do that from within the EXEC and
@err of course is out of scope outside of EXEC.
How can I accomplish this or something equivalent?
Thanks yet again
ds
I use the exec statement because I want to
get info from a table
which is known through a parameter.
for example I have:
/* begin SQL */
create [sp]
@tablename varchar(50)
AS
exec ('
declare @err int
set @err =
(select count(*) from '+@tablename+' where a=1)
')
But I want to be able to return @err. Unfortunately
I can;t seem to do that from within the EXEC and
@err of course is out of scope outside of EXEC.
How can I accomplish this or something equivalent?
Thanks yet again
ds