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)
 loop through a select statement???

Author  Topic 

jgn1013
Starting Member

24 Posts

Posted - 2009-02-17 : 16:39:11
table A
---------
region..id
J.......11
J.......12
Z.......13
Z.......14
Z.......15

table B
---------
id....title
11....Accountant
12....Artist
12....Programmer
13....Nurse


select id from tableA where region='J'
loop through value 11,12
select id,title from tableB where tableA.id = 11 or 12

result
11....Accountant
12....Artist
12....Programmer

not really sure if looping is the way to go.

TIA

mfemenel
Professor Frink

1421 Posts

Posted - 2009-02-17 : 16:44:01
select b.ID, b.title
from tablea a
inner join tableb b on a.region=b.id
where a.region in(11,12)

Mike
"oh, that monkey is going to pay"
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-17 : 16:57:53
quote:
Originally posted by mfemenel

select b.ID, b.title
from tablea a
inner join tableb b on a.id=b.id
where a.region in(11,12)



Mike
"oh, that monkey is going to pay"

Go to Top of Page

mfemenel
Professor Frink

1421 Posts

Posted - 2009-02-17 : 21:00:28
woops. Thanks sodeep.

Mike
"oh, that monkey is going to pay"
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-17 : 22:55:02
quote:
Originally posted by sodeep

quote:
Originally posted by mfemenel

select b.ID, b.title
from tablea a
inner join tableb b on a.id=b.id
where a.region = 'j' in(11,12)



Mike
"oh, that monkey is going to pay"



Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-17 : 23:03:35
quote:
Originally posted by bklr

quote:
Originally posted by sodeep

quote:
Originally posted by mfemenel

select b.ID, b.title
from tablea a
inner join tableb b on a.id=b.id
where a.id in (11,12)



Mike
"oh, that monkey is going to pay"





Go to Top of Page
   

- Advertisement -