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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Return number of rows using dynamic statement

Author  Topic 

srad
Starting Member

39 Posts

Posted - 2001-08-21 : 04:39:09
Any idea how i can return the number of rows from a table when i execute the statement using execute sp_executesql??

** This does not work because the @count variable is out of scope of the
execute statement. (note @tablename is supplied as an input parameter to an sp.)
declare
@sqlstring nvarchar(400),
@count int

select @sqlstring = 'SELECT @count = (count(*)FROM' + @tablename + ')'
EXECUTE sp_executesql @sqlstring




   

- Advertisement -