Link to home
Start Free TrialLog in
Avatar of rsrsm
rsrsm

asked on

Avoiding loop to get a resultset

Let me explain the scenario (SQL 2000 DTS):
I've a order table and order_detail table.
Order_detail table refers Order table for order_id. Since one order can have multiple items within it we've the order_detail table. So Order->order_detail is a one->many relationship.
Now I want to export the data into a flat file. the format is something like this:

order1_id, order number, date
Order_detail_id1,item_name1
Order_detail_id2, item_name2
order2_id, order number, date
order_detail_id3,item_name3
order_detail_id4, item_name4

So I need to write one line from the order table and then follows the corresponding order_detail table records. Again need to write the order table record and so on. Is there way to do this other looping? I knw we can use a while loop or cursor, I want to know if therz a better way of writing this in t-SQL only avoiding loop.

regards
ASKER CERTIFIED SOLUTION
Avatar of Ved Prakash Agrawal
Ved Prakash Agrawal
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Lowfatspread
Lowfatspread
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rsrsm
rsrsm

ASKER

Thank you both since both the answers were quick and almost similar I've divided the points. Please let me know if there are any concerns.