How to combine different rows in SQL Server? -


query:

select      ag.agentid agentid, ag.agentname agentname,     case when pc.contacttypecd='m' pc.contactnum end 'mobile',     case when pc.contacttypecd='r' pc.contactnum end 'residence',     case when pc.contacttypecd='em' pc.contactnum end 'emergency_no'      agent ag  left join      party p on p.partyid = ag.partyid left join       partycontact pc on pc.partyseq = p.partyseq      ag.agentid = '10000005' 

output

enter image description here

expected output
enter image description here

try this:

select ag.agentid agentid, ag.agentname agentname,        max(case when pc.contacttypecd='m' pc.contactnum end) 'mobile',        max(case when pc.contacttypecd='r' pc.contactnum end) 'residence',        max(case when pc.contacttypecd='em' pc.contactnum end) 'emergency_no' agent ag  left join party p on p.partyid = ag.partyid left join partycontact pc on pc.partyseq = p.partyseq ag.agentid = '10000005' group ag.agentid, ag.agentname 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -