sql - How to write a select inside case statement -


i have stored procedure contains case statement inside select statement.

select invoice_id, 'unknown' invoice_status,  case when invoice_printed null '' else 'y' end invoice_printed,  case when invoice_deliverydate null '' else 'y' end invoice_delivered,  case when invoice_deliverytype <> 'usps' '' else 'y' end invoice_edeliver,  invoice_contactlname+', '+invoice_contactfname contactname,  dbo.invoice left outer join dbo.fninvoicecurrentstatus() on invoice_id=cust_invoiceid  cust_statusid= 7  order inv_created   

at line case when invoice_deliverytype <> 'usps' '' else 'y' end invoice_edeliver

i need check valid email address (if email valid, display y, else display n).

so line read:

if invoice_deliverytype <> 'usps' '' else ( if isnull(select emailaddr dbo.client client_id = substring(invoice_id, 1, 6)), 'y', 'n')

how can write out query?

you can case. think following logic want:

(case when invoice_deliverytype <> 'usps' ''       when exists (select 1                    dbo.client c                    c.client_id = substring(i.invoice_id, 1, 6) ,                          c.emailaddr not null                   )       'y'       else 'n'  end) 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -