vendredi 26 juin 2015

connecting multiple databases, and want a result using an if statement

/Returns a value of FMCSA if the carrier only has the paperwork with the code 22, if they have other paperwork return the value of null./
I am trying to figure out why it will not work within my query as a select statement and I keep getting an error for the keyword Then.

Would it be better to use a case statement? if so how would I do that.

,if exists(select * from orderheader oh left join CARRIER as c on oh.ord_carrier = c.car_id left outer join city as y on c.cty_code = y.cty_code inner join labelfile as l on c.car_status = l.abbr left join safetyreport as s on s.srp_carrier = c.car_id left join trlaccessories as t on t.ta_trailer = s.srp_carrier where cast(floor(cast(c.car_createdate as float)) as datetime) between '2015-06-20' AND '2015-06-25' AND labeldefinition = 'CarStatus') begin (Select m.carrier_id from carrier as cr left join cowsql01.carrier_imaging.dbo.main as m on cr.car_id = m.carrier_id inner join cowsql01.carrier_imaging.dbo.DocTypes as ty on m.in_doctypeid = ty.in_doctypeid where cr.car_id = m.carrier_id and m.in_doctypeid in ('10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '23', '24', '25', '26') Then 'Null' Else m.in_doctypeid = '22' Then 'Only FMCSA' End

Aucun commentaire:

Enregistrer un commentaire