Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting row count as part of DB design info
Message
 
 
To
04/02/2008 11:04:54
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01289085
Message ID:
01289094
Views:
13
This message has been marked as a message which has helped to the initial question of the thread.
You can use dynamic sql
DECLARE @sql nvarchar(4000) 
...
--SET @RowCount = (SELECT COUNT (*) FROM @TableName)
SET @sql = 'SELECT @RowCount = COUNT (*) FROM ' + @TableName
EXEC sp_executesql @sql, N'@RowCount int OUTPUT', @RowCount OUTPUT
>I am trying to create a DB design document for a legacy DB. Part of this is the row count of each table. I have put together the following query, but it chokes at the line indicated (inside the cursor).
>
> Msg 1087, Level 15, State 2, Line 44
> Must declare the table variable "@TableName".
>
>All help is always appreciated.
>
>Line of error:
>
>  	SET @RowCount = (SELECT COUNT (*) FROM @TableName)
>
>
<snip>
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform