Many to many with multiple rows in SQL Server -


i have table containing following columns:

seq_no | detail_no |user_id |guid_key

and table following:

header| guid_key| date_entered| login_details| summary_transaction| trailer

now wish map 2 tables such final answer way:

the first row should value header , subsequent rows should values seq_no, detail_no , user_id. there multiple rows of seq_no, detail_no , user_id. last row should trailer.

the first table contains multiple rows need referenced multiple rows in second table. i'm new sql programming. i've looked many-many relationships unable find efficient way this. using guid generator write unique keys both tables. however, key not unique per row rather set of rows--> set of data.

this how want be

sql not presentation tool you're trying achieve here. you're trying make 2 results sets present 1 result set (you want columns table 1 on rows on columns table 2 on others).

create table #temp (id int identity(1,1), col1 varchar(200), col2 varchar(200) etc.)  insert #temp col1, col2, etc values (select seq_no, guid_key, detail_no, user_id table1)  insert #temp col1, col2 etc. values (select seq_no, guid_key, header,  date_entered, login_details, summary_transaction table1 inner join table2 on table1.guid_key = table2.guidkey trailer null)  insert #temp col1, col2 etc. values (select seq_no, guid_key, trailer,  date_entered, login_details, summary_transaction table1 inner join table2 on table1.guid_key = table2.guidkey trailer not null)  select * #temp order col1, id 

so enter headers first followed detail, followed trailer. when order seq_no , id come out in order desired.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -