Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Variable in 'from' clause
Message
 
 
To
15/08/2007 10:19:35
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01248239
Message ID:
01248240
Views:
22
This message has been marked as a message which has helped to the initial question of the thread.
You can either use dynamic SQL or undocumented stored procedure sp_MSforeachtable http://www.mssqlcity.com/Articles/Undoc/SQL2000UndocSP.htm

>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
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform