Select multiple rows to columns in SQL server -
i want below output through sql server.
table a
| id | name | 2016 | 2017 | - - - - - - - - - - - - - - - - | 1 | abcdefg | | | | 2 | xyzlmon | | |
table b
| id | value | year | - - - - - - - - - - - | 1 | f | 2016 | | 1 | g | 2017 |
output
| id | name | 2016 | 2017 | - - - - - - - - - - - - - - - - | 1 | abcdefg | f | g | | 2 | xyzlmon | | |
try this:
select tbla.id id, tbla.name name, (select value tblb tblb.id = tbla.id , tblb.year ='2016') 2016, (select value tblb tblb.id = tbla.id , tblb.year ='2017') 2017 tbla;
Comments
Post a Comment