Guest User

Untitled

a guest
Oct 21st, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. select TRADENAME as TENTHUOC,VALUE,C_UOM, UNITPRICE_SERVICE
  2. ,sum (case HIS_DEPARTMENT_ID when 1000233 then totalquantity else 0 end) LAO_X
  3. ,sum (case HIS_DEPARTMENT_ID when 1000234 then totalquantity else 0 end) HSTC_X
  4. ,sum (case HIS_DEPARTMENT_ID when 1000235 then totalquantity else 0 end) Noi_TH_X
  5. ,sum (case HIS_DEPARTMENT_ID when 1000236 then totalquantity else 0 end) HH_X
  6. ,sum (case HIS_DEPARTMENT_ID when 1000237 then totalquantity else 0 end) G_X
  7. ,sum (case HIS_DEPARTMENT_ID when 1000238 then totalquantity else 0 end) Ngoai_TH_X
  8. ,sum (case HIS_DEPARTMENT_ID when 1000239 then totalquantity else 0 end) NHI_X
  9. ,sum (case HIS_DEPARTMENT_ID when 1000247 then totalquantity else 0 end) KKB_X
  10. ,sum (case HIS_DEPARTMENT_ID when 1000261 then totalquantity else 0 end) UB_X
  11. ,sum (case HIS_DEPARTMENT_ID when 1000264 then totalquantity else 0 end) PNN_X
  12. ,sum (case HIS_DEPARTMENT_ID when 1000268 then totalquantity else 0 end) DKTYC_X
  13. ,sum (case HIS_DEPARTMENT_ID when 1000269 then totalquantity else 0 end) PMT_X
  14. ,sum (case HIS_DEPARTMENT_ID when 1000270 then totalquantity else 0 end) GMHS_X
  15. ,sum (case HIS_DEPARTMENT_ID when 1000271 then totalquantity else 0 end) PHCN_X
  16. ,sum (case HIS_DEPARTMENT_ID when 1000272 then totalquantity else 0 end) PTLN_X
  17. ,sum (case HIS_DEPARTMENT_ID when 1000313 then totalquantity else 0 end) CMU_X
  18. ,sum (case HIS_DEPARTMENT_ID when 1000333 then totalquantity else 0 end) CC_X
  19.  
  20. ,sum (case HIS_DEPARTMENT_ID when 1000233 then RETURNEDQUANTITY else 0 end) LAO_T
  21. ,sum (case HIS_DEPARTMENT_ID when 1000234 then RETURNEDQUANTITY else 0 end) HSTC_T
  22. ,sum (case HIS_DEPARTMENT_ID when 1000235 then RETURNEDQUANTITY else 0 end) Noi_TH_T
  23. ,sum (case HIS_DEPARTMENT_ID when 1000236 then RETURNEDQUANTITY else 0 end) HH_T
  24. ,sum (case HIS_DEPARTMENT_ID when 1000237 then RETURNEDQUANTITY else 0 end) G_T
  25. ,sum (case HIS_DEPARTMENT_ID when 1000238 then RETURNEDQUANTITY else 0 end) Ngoai_TH_T
  26. ,sum (case HIS_DEPARTMENT_ID when 1000239 then RETURNEDQUANTITY else 0 end) NHI_T
  27. ,sum (case HIS_DEPARTMENT_ID when 1000247 then RETURNEDQUANTITY else 0 end) KKB_T
  28. ,sum (case HIS_DEPARTMENT_ID when 1000261 then RETURNEDQUANTITY else 0 end) UB_T
  29. ,sum (case HIS_DEPARTMENT_ID when 1000264 then RETURNEDQUANTITY else 0 end) PNN_T
  30. ,sum (case HIS_DEPARTMENT_ID when 1000268 then RETURNEDQUANTITY else 0 end) DKTYC_T
  31. ,sum (case HIS_DEPARTMENT_ID when 1000269 then RETURNEDQUANTITY else 0 end) PMT_T
  32. ,sum (case HIS_DEPARTMENT_ID when 1000270 then RETURNEDQUANTITY else 0 end) GMHS_T
  33. ,sum (case HIS_DEPARTMENT_ID when 1000271 then RETURNEDQUANTITY else 0 end) PHCN_T
  34. ,sum (case HIS_DEPARTMENT_ID when 1000272 then RETURNEDQUANTITY else 0 end) PTLN_T
  35. ,sum (case HIS_DEPARTMENT_ID when 1000313 then RETURNEDQUANTITY else 0 end) CMU_T
  36. ,sum (case HIS_DEPARTMENT_ID when 1000333 then RETURNEDQUANTITY else 0 end) CC_T
  37.  
  38. ,sum(TOTALQUANTITY - RETURNEDQUANTITY) total
  39. from HIS_BC_XUATTHUOC
  40. where 1=1
  41. and (HIS_STORAGE_ID = $P{HIS_Storage_ID} or $P{HIS_Storage_ID} is null)
  42. and HIS_DEPARTMENT_ID not in (1000273,0) and HIS_DEPARTMENT_ID is not null
  43. and (HIS_DEPARTMENT_ID = $P{HIS_DEPARTMENT_ID} or $P{HIS_DEPARTMENT_ID} is null)
  44. and (HIS_MEDICINECLASSIFY_ID = $P{HIS_MedicineClassify_ID} or $P{HIS_MedicineClassify_ID} is null)
  45. and (HIS_MEDICINEGROUP_ID = $P{HIS_MedicineGroup_ID} or $P{HIS_MedicineGroup_ID} is null)
  46. and (HIS_PATIENTTYPE_ID = $P{HIS_PATIENTTYPE_ID} or $P{HIS_PATIENTTYPE_ID} is null)
  47. and (HIS_SERVICE_ID = $P{HIS_Service_ID} or $P{HIS_Service_ID} is null)
  48. and (INOUT=$P{INOUT} or $P{INOUT} is null)
  49. AND (ISINPATIENT = $P{ISINPATIENT} OR $P{ISINPATIENT} IS NULL)
  50. and (ISFREEBYAPPROVAL = $P{ISFREEBYAPPROVAL} or $P{ISFREEBYAPPROVAL} is null)
  51. and ((ACTDATE between $P{FromDate} and $P{ToDate} AND TYPE in ('In_Import','In_Export')) OR (VERIFIEDDATE between $P{FromDate} and $P{ToDate} AND TYPE in ('Out_Export')))
  52. and HIS_DEPARTMENT_ID in (1000233,1000234,1000235,1000236,1000237,1000238,1000239,1000247,1000261,
  53. 1000264,1000268,1000269,1000270,1000271,1000272,1000313,1000333)
  54. group by TRADENAME,C_UOM,UNITPRICE_SERVICE,VALUE
  55. order by TRADENAME,UNITPRICE_SERVICE
Add Comment
Please, Sign In to add comment