PDA

View Full Version : Please help with advance querry


edfx21
10-11-2004, 01:32 PM
Ok I need to come up with the this query
I have 2 identical tables consisting of 1 columns each

1st table
ID
01
02
03

2nd table
ID
01
02
03
04
05
06
07
08
09


Now for each element in table 1 I need to select 3 elements in table 2. The logic being is that MAX of 2nd table has to divide on MAX of 1st table and with number achieved from that division I need to select for each element in table 1 the number of elements in sequential order from table 2

Example for the needed output: the elements separated by coma
01,01
01,02
01,03
02,04
02.05
02,06
03,07
03,08
03,09

I need to have this query in a proc don in MS SQL
Any help would be greatly appreciated
Thank you.