Guest User

Untitled

a guest
Apr 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. select
  2. CONVERT(VARCHAR(10), orders.orderdate, 101) as 'Date',
  3. orders.patientid as 'Pt ID',
  4. (SELECT CASE WHEN EXISTS (select orderid from orderitems where itemid in (250,249) and orderitems.orderid = orders.orderid) THEN 'EXAM' ELSE '' END) AS 'Exam',
  5. (SELECT CASE WHEN EXISTS (select orderid from orderitems where itemtype = 'F' and itemid is not null and orderitems.orderid = orders.orderid) THEN 'FRAME' ELSE '' END) AS 'Frame',
  6. (SELECT CASE WHEN EXISTS (select orderid from orderitems where itemtype = 'S' and description like '%system%' and orderitems.orderid = orders.orderid) THEN 'LENS' ELSE '' END) AS 'Lens'
  7. from orders
  8. where ordertypeid in (999,9,1026) ---999 = Other, 1026 = Spec Lens, 9 = Frame
  9. and (orderstatusid not in (24,26,2944,1141,69) --Excludes bad orders
  10. OR orderstatusid is null) --no status OK for exams
  11. and orderdate between '2015-01-01' and '2015-12-31'
  12. and remake_orderid is null
  13. order by patientid
Add Comment
Please, Sign In to add comment