sql server 2008 - Combine 2 sql table rows into one -
sql server 2008 - Combine 2 sql table rows into one -
i'm trying combine below rows 1 record report. looking [loan officer] , [realtor] names show on 1 line. help appreciated.
here now
select distinct z.state ,z.county ,z.city ,cr.zipcode ,cr.route ,upper(c1.lastname) + ', ' + upper(c1.firstname) 'loan officer' ,upper(c2.lastname) + ', ' + upper(c2.firstname) 'realtor' ,cr.id prospecting.zipcodecarrierroute cr (nolock) inner bring together zipcodes z (nolock) on z.zipcode = cr.zipcode left bring together prospecting.contact_carriercode_assignments cca (nolock) on cca.zipcodecarrierrouteid = cr.id left bring together prospecting.contact c1 (nolock) on c1.contactid = cca.contactid , c1.contacttypeid = 1 left bring together prospecting.contact c2 (nolock) on c2.contactid = cca.contactid , c2.contacttypeid = 2 cr.id = 875
this results
this looking
you can readily group by
:
select z.state, z.county, z.city, cr.zipcode, cr.route, max(upper(c1.lastname) + ', ' + upper(c1.firstname)) [loan officer], max(upper(c2.lastname) + ', ' + upper(c2.firstname)) [realtor], cr.id prospecting.zipcodecarrierroute cr (nolock) inner bring together zipcodes z (nolock) on z.zipcode = cr.zipcode left bring together prospecting.contact_carriercode_assignments cca (nolock) on cca.zipcodecarrierrouteid = cr.id left bring together prospecting.contact c1 (nolock) on c1.contactid = cca.contactid , c1.contacttypeid = 1 left bring together prospecting.contact c2 (nolock) on c2.contactid = cca.contactid , c2.contacttypeid = 2 cr.id = 875 grouping z.state, z.county, z.city, cr.zipcode, cr.route, cr.id
sql sql-server-2008
Comments
Post a Comment