Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Variable in 'from' clause
Message
De
15/08/2007 10:19:35
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Variable in 'from' clause
Divers
Thread ID:
01248239
Message ID:
01248239
Vues:
63
I am trying to atomate getting the count of rows in each user table in a given database. I tried the following, but got an error saying the table variable needs to be declared. ?? I assume from this that a variable can not be put in the 'from' clause. Is there another way to do this?
DECLARE @TableName	varchar(80)

DECLARE TableInfo CURSOR
FOR 
SELECT [Name]
FROM sys.tables
OPEN TableInfo
FETCH NEXT FROM TableInfo INTO @TableName
WHILE @@fetch_status = 0
BEGIN
	Select @TableName, count(*) From @TableName

	FETCH NEXT FROM TableInfo INTO @TableName
END
CLOSE TableInfo 
DEALLOCATE TableInfo
Thank You

Rollin Burr

Politicians and diapers have one thing in common. They should both be changed regularly, and for the same reason.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform