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
Post a Comment