Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting row count as part of DB design info
Message
 
 
À
04/02/2008 11:04:54
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01289085
Message ID:
01289094
Vues:
14
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--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform