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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 For loop in sql server

Author  Topic 

bpuccha
Starting Member

34 Posts

Posted - 2012-06-14 : 15:02:00
Hi,

Do we have for loop in sql server 2000?

How to do the below scenario in sql server

Table1:
name id amt
----------
vbjh 1 1000
guhu 2 3000
bjkh 4 1000


Code in Orcale:
begin
for i in (select id from table1)
loop
dbms.output('i')
end loop
end

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-14 : 15:42:28
you just need

SELECT id FROM table1


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-06-14 : 15:44:27
I can't read your Oracle code. Please tell us what it does so we can suggest a T-SQL solution.

Or just run this: select id from table1

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

bpuccha
Starting Member

34 Posts

Posted - 2012-06-14 : 15:53:51
My scenario is like this

I have a property table with the below details

p_no t_no r_no r_p
------------------
00001 001 2 PQ
00001 001 4 PQ
00001 001 1 ON
00001 001 3 ON
00001 001 5 ON


I have 9 queries , I created a table valued function to return the data from all these 9 queries.

For r_no's 2 ,4 i have to run the query1 and isnert the data into a table,
again for 2 and 4 run the query 2 and isnert the data into a table....so on
again 2 and 4 run the query 9 and isnert the data into a table

In order to execute Query1 i have so many if and else conditions based on the if and else condition the query may change slightly.


Once I run all the queries fr=or r_no 2 and 4 , again i have to repeat the same thing from r_no's 1,3,5
The order of insertion is important here...
How to do this in sql server 2000 ?


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-14 : 17:09:39
are conditions for groups different? why do you need separate queries for each?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bpuccha
Starting Member

34 Posts

Posted - 2012-06-15 : 09:22:34
Yes..The conditions will be different for each group and queries also differs for each group...
Go to Top of Page
   

- Advertisement -