Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Bernard_za
Starting Member
6 Posts |
Posted - 2003-03-04 : 03:13:12
|
| I am trying to perform a COUNT(*) result into a table that should hold the TABLE_NAME and TABLE_COUNT for each table that the cursor picks up on.The result should look like this:---------------------------------TABLE_NAME | TABLE_COUNT---------------------------------tbl_Table1 | 1250tbl_Table2 | 450tbl_Table3 | 1050tbl_Table4 | 2505I write a query as follows:---------------------------DECLARE @SQL_CURSOR CURSORDECLARE CUR_SOR CURSOR FOR SELECT name FROM sysobjects WHERE name LIKE 'tbl_%' ORDER BY nameSET @SQL_CURSOR = CUR_SOROPEN CUR_SORFETCH NEXT FROM CUR_SORWHILE @@FETCH_STATUS = 0BEGINDECLARE @STATEMENT VARCHAR(100)SET @STATEMENT = 'SELECT COUNT(*) FROM ' + @SQL_CURSOREXEC (@STATEMENT)FETCH NEXT FROM CUR_SORENDCLOSE CUR_SORDEALLOCATE CUR_SORThe error I get is as follows:------------------------------Server: Msg 206, Level 16, State 2, Line 14Operand type clash: varchar is incompatible with cursorServer: Msg 403, Level 16, State 1, Line 14Invalid operator for data type. Operator equals add, type equals cursor.Please Help! |
|
|
macka
Posting Yak Master
162 Posts |
Posted - 2003-03-04 : 04:20:58
|
| Slight modification to the query in [url]http://www.sqlteam.com/Forums/topic.asp?TOPIC_ID=14624[/url] gives you:SELECT so.name as TABLE_NAME,si.rows as TABLE_COUNTFROM sysindexes siINNER JOIN sysobjects so ON si.id = so.idWHERE si.indid in (0,1) AND so.type = 'U' AND so.name like 'tbl_%'ORDER BY so.namemacka. --There are only 10 types of people in the world - Those who understand binary, and those who don't. |
 |
|
|
Bernard_za
Starting Member
6 Posts |
Posted - 2003-03-04 : 04:37:51
|
| Thanks! This works just great! 101010101010101010101010101010 |
 |
|
|
|
|
|