Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Variable in 'from' clause
Message
From
15/08/2007 10:19:35
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Variable in 'from' clause
Miscellaneous
Thread ID:
01248239
Message ID:
01248239
Views:
62
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.
Next
Reply
Map
View

Click here to load this message in the networking platform