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_name 1
Order_detail_id2, item_name2
order2_id, order number, date
order_detail_id3,item_name 3
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
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_name
Order_detail_id2, item_name2
order2_id, order number, date
order_detail_id3,item_name
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER