Re: calling a stored procedure in a while loop
- From: Vic <vikrantp@xxxxxxxxx>
- Date: Sat, 23 Feb 2008 11:04:52 -0800 (PST)
On Feb 22, 7:21 pm, "Plamen Ratchev" <Pla...@xxxxxxxxxxxxx> wrote:
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
So it seems like I don't really have to look into the Information
shcema for TestData6061, these table names can be accessed as
SELECT DISTINCT ObjectClass
FROM SchemaFields
ORDER BY ObjectClass
and that will give me something like this ->
accounting
fundstructures
investment
party
price
reference
sync
systemsettings
transaction
twr
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
.
- Follow-Ups:
- Re: calling a stored procedure in a while loop
- From: Hugo Kornelis
- Re: calling a stored procedure in a while loop
- References:
- calling a stored procedure in a while loop
- From: Vic
- Re: calling a stored procedure in a while loop
- From: Plamen Ratchev
- calling a stored procedure in a while loop
- Prev by Date: Re: Want to learn SQL in California....any school, literature recommendations?
- Next by Date: Re: sql query which has got 3 dynamic parameters
- Previous by thread: Re: calling a stored procedure in a while loop
- Next by thread: Re: calling a stored procedure in a while loop
- Index(es):
Relevant Pages
|