Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
select row as column from one Table_1 and assign values from Table_3

Table_1
id------Name
1------A
2------B
3------C
4------D

Table_2
id------invoice_no
1------inv-1
2------inv-2
3------inv-3

Table_3
id------Table_1_id------Table_2_id------value
1------1 ------1 ------p
2------2 ------1 ------q
3------3 ------1 ------r
4------4 ------1 ------s
5------1 ------2 ------t
6------2 ------2 ------u
7------1 ------3 ------v

Answer
Table_2_id-------A-------B-------C-------D
1---------------p-------q-------r-------s
2---------------t-------u------- -------
3---------------v------- ------- -------
Posted

1 solution

I thing you required cross table type output.
So here I am putting an example that hope will help you out.

SQL
select * from Table_1
pivot (max (id) for Name in ([A],[B],[C],[D])) as NameIDDets


You can customized it and google about ms sql server pivot for more details.

Have a good day !!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900