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 2005 Forums
 Transact-SQL (2005)
 Selecting the data

Author  Topic 

sudha12345
Starting Member

47 Posts

Posted - 2009-04-25 : 07:58:48
I has two tables infusion,serverlist which has rows like

infusion
serverid cusomerid name age
1101 1 we 25
1101 1 mm 32
1101 2 qs 28
1102 1 rd 35
1102 1 km 82
1102 1 rk 54
1102 2 kl 17
1102 3 rm 45
1103 1 rd 56

serverlist
serverid customerid
1101 1
1101 2
1102 1
1102 2
1102 3
1103 1

now i want the output that

the first row of serverlist has to match with records of infusion and return those records that has matched and insert ino another table which like infusion.
the second row of serverlist has to match with records of infusion and return those records that has matched and insert ino another table which like infusion.
the third row of serverlist has to match with records of infusion and return those records that has matched and insert ino another table which like infusion.
and so on till end
note that the records in serverlist are not fixed, there may be 3 or 4 or 5. its not fixed

Sudhakar

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-04-25 : 11:43:42
[code]
insert into table_like_infusion(
serverid,
cusomerid,
name,
age)
select i.serverid, i.cusomerid, i.name, i.age
from (select distinct serverid from serverlist) s
join infusion i on i.serverid = s.serverid
[/code]

Webfred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -