Question : SQL Select query


--generate report #1
I need to modify the select query below to all write to one column
select
       cr.a  'name1',
       cg.b  'name2',
       i.c      'name3'
I have tried
select
       cr.a  ^  cg.b  ^   i.c      'name3'

but get the following error
The data types nvarchar and nvarchar are incompatible in the boolean XOR operator

is there a way to have it so that if a value from table cr, column a OR value from table cg column b OR value from table i column c AS 'Name'

Cheers

Answer : SQL Select query

Best to use proper ANSI joins instead of mixing.

select cn.userid           'UserID',
       cn.first_name +' ' + cn.last_name    'Name',
       org.org_name      'BSL',
       loc.location_name 'Location',
       x.a 'name'
 from  ((table1 cr left outer join table2 cn on cn.contact = cr.customer)left outer join table3 cg on cn.contact = cg.[user])
left outer join table4 i on cn.contact= i.request
cross join organisation org
cross join location loc
outer apply (
      select a=convert(varchar(max),cr.a) where cr.a is not null
      union all
      select cg.b where cg.b is not null
      union all
      select i.c where i.c is not null) x
where cn.location_id = loc.location_id
Random Solutions  
 
programming4us programming4us