![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
I just tested your code on one of my test databases and it retuned 12 rows (but I have have over 200 tables there, and permissions to all of them). A few things to check: * How many tables do you have in the TestData6061 database? You need to have at least 29 to see 12 rows as result. * Do you have permissions to the tables in the TestData6061 database? The information schema views let you see only objects for which you have permissions. Also, it just seems a bit odd that your SP is in the Releases database but references the information schema views in the TestData6061 database. Try to run the query below. Essentially it is equivalent to your stored procedure and the loop combined together in one query. You can comment out the WHERE clause to see all tables. If you are on SQL Server 2005 you can replace the subquery calculating the seq column using ROW_NUMBER, like ROW_NUMBER() OVER(ORDER BY table_name). SELECT table_name, seq FROM ( SELECT table_name, (SELECT COUNT(*) FROM TestData6061.INFORMATION_SCHEMA.Tables AS B WHERE A.table_name >= B.table_name) FROM TestData6061.INFORMATION_SCHEMA.Tables AS A) AS T(table_name, seq) WHERE seq IN (1, 4, 7, 8, 14, 17, 18, 22, 25, 27, 28, 29) HTH, Plamen Ratchevhttp://www.SQLStudio.com |
#4
| |||
| |||
|
|
Now coming back to the looping, I basically want to have a sql query which will loop through the above list (accounting, investment, etc etc) giving me the single value as it goes through the loop. Thanks in advance |
#5
| |||
| |||
|
|
On Sat, 23 Feb 2008 11:04:52 -0800 (PST), Vic wrote: (snip) Now coming back to the looping, I basically want to have a sql query which will loop through the above list (accounting, investment, etc etc) giving me the single value as it goes through the loop. Thanks in advance Hi Vic, Why? SQL Server is optimized for set-based operations. There are some casees where iterating over a result set and processing rows one by one is better, but they are seldom. If you can explain what you try to achieve, we might be able to point you towards a better way. Anyway, if you insist on doing this, read up on cursors in Books Online. -- Hugo Kornelis, SQL Server MVP My SQL Server blog:http://sqlblog.com/blogs/hugo_kornelis |
#6
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |