CASE statement IF ELSE in SQL Server -
i have select statement , trying accomplish data in the
 dosageperunits column if dosage not equal empty or 1 , if units not empty or 1. 
can me please ?
select      sbd.code, c.description, sbd.dosage,      case          when sbd.units = '' '1'          else sbd.units      end units,      ad.apptdate, sbd.rcycle, sbd.rweek, sbd.rday,      t.historyorder, t.typeid, sbd.dosage + '/' + sbd.unitsas dosageperunits     bill_superbilldetail sbd,      bill_procedureverification pv,      appointmentdata ad,     cptcode c,      cpttype t      sbd.accessionnumber = pv.accessionnumber     , pv.apptid = ad.apptid     , ad.patientid = 443     , ad.apptdate <= getdate()     , ad.apptdate > '2009-11-15 00:00:00.000'     , c.typeid = t.typeid      
according description, should this:
case when isnull(sbd.dosage, '1') <> '1' , isnull(sbd.units, '1') <> '1' sbd.dosage + '/' + sbd.units else null end dosageperunits   isnull(x, 1) replaces x 1 if null. isnull(x, 1)  = 1 if x either 1 or null.
edit: changed assumption [dosage] , [unit] both varchar comment indicates.
Comments
Post a Comment