Row as column in sql server -


i have table below in sql server 2008

location       lob               unitname ----------     ---------         ------------------- chennai         health           unitb mumbai          health           unitb pune            health           unita,unitb chennai         motor            unitb mumbai          motor            unitb pune            motor            unitb,unitc trivandum       motor            unitc 

and expecting result below..

location       health            motor ---------      --------          -------- chennai        unitb             unitb mumbai         unitb             unitb pune           unita,unitb       unitb,unitc trivandum                        unitc 

i need query display this. can me achieve this??

try this:

select distinct location,         isnull((select unitname table_name t1 t1.location=t.location , t1.lob= 'health'),'') health,         isnull((select unitname table_name t2 t2.location=t.location , t2.lob= 'motor'),'') motor table_name t 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -