brass.sql 3.5 KB

12345678910111213141516171819202122232425262728
  1. select distinct case
  2. when T1."ACCT_NR" in (
  3. '8310',
  4. '8300',
  5. '8301',
  6. '8311',
  7. '7310',
  8. '7300',
  9. '7301',
  10. '7800'
  11. ) then { fn CONCAT(
  12. { fn CONCAT(
  13. { fn RTRIM(
  14. case
  15. when { fn LEFT(T1."ACCT_NR", 1) } in ('7', '8')
  16. and case
  17. when { fn LEFT(T1."ACCT_NR", 1) } in ('4', '7', '8', '5') then { fn CONCAT(
  18. { fn CONCAT({ fn LEFT(T1."ACCT_NR", 4) }, '_') },
  19. case
  20. when T2."DEPARTMENT" = ' ' then '00'
  21. else T2."DEPARTMENT"
  22. end
  23. ) }
  24. else T1."ACCT_NR"
  25. end like '%\_%' escape '\' then {fn CONCAT({fn CONCAT({fn RTRIM(case when {fn LEFT(T1."ACCT_NR",1)} in (' 4 ', ' 7 ', ' 8 ', ' 5 ') then {fn CONCAT({fn CONCAT({fn LEFT(T1."ACCT_NR",4)},' _ ')},case when T2."DEPARTMENT" = ' ' then ' 00 ' else T2."DEPARTMENT" end )} else T1."ACCT_NR" end )},' _ ')},{fn RTRIM(case when T2."CLIENT_DB" in (' deop01 ', ' deop02 ') and case when (T2."DESTINATION" is null or T2."DESTINATION" = ' ') then ' 00 ' else T2."DESTINATION" end = ' 50 ' then ' 30 ' when T2."CLIENT_DB" in (' deop01 ', ' deop02 ') and case when (T2."DESTINATION" is null or T2."DESTINATION" = ' ') then ' 00 ' else T2."DESTINATION" end in (' 90 ', ' 91 ') then ' 50 ' else case when T2."DESTINATION" is null or T2."DESTINATION" = ' ' then ' 00 ' else T2."DESTINATION" end end )})} else case when {fn LEFT(T1."ACCT_NR",1)} in (' 4 ', ' 7 ', ' 8 ', ' 5 ') then {fn CONCAT({fn CONCAT({fn LEFT(T1."ACCT_NR",4)},' _ ')},case when T2."DEPARTMENT" = ' ' then ' 00 ' else T2."DEPARTMENT" end )} else T1."ACCT_NR" end end )},' _ ')},T2."PRODUCT_GROUP")} else case when {fn LEFT(T1."ACCT_NR",1)} in (' 7 ', ' 8 ') and case when {fn LEFT(T1."ACCT_NR",1)} in (' 4 ', ' 7 ', ' 8 ', ' 5 ') then {fn CONCAT({fn CONCAT({fn LEFT(T1."ACCT_NR",4)},' _ ')},case when T2."DEPARTMENT" = ' ' then ' 00 ' else T2."DEPARTMENT" end )} else T1."ACCT_NR" end like ' % \ _ %' escape ' \ ' then {fn CONCAT({fn CONCAT({fn RTRIM(case when {fn LEFT(T1."ACCT_NR",1)} in (' 4 ', ' 7 ', ' 8 ', ' 5 ') then {fn CONCAT({fn CONCAT({fn LEFT(T1."ACCT_NR",4)},' _ ')},case when T2."DEPARTMENT" = ' ' then ' 00 ' else T2."DEPARTMENT" end )} else T1."ACCT_NR" end )},' _ ')},{fn RTRIM(case when T2."CLIENT_DB" in (' deop01 ', ' deop02 ') and case when (T2."DESTINATION" is null or T2."DESTINATION" = ' ') then ' 00 ' else T2."DESTINATION" end = ' 50 ' then ' 30 ' when T2."CLIENT_DB" in (' deop01 ', ' deop02 ') and case when (T2."DESTINATION" is null or T2."DESTINATION" = ' ') then ' 00 ' else T2."DESTINATION" end in (' 90 ', ' 91 ') then ' 50 ' else case when T2."DESTINATION" is null or T2."DESTINATION" = ' ' then ' 00 ' else T2."DESTINATION" end end )})} else case when {fn LEFT(T1."ACCT_NR",1)} in (' 4 ', ' 7 ', ' 8 ', ' 5 ') then {fn CONCAT({fn CONCAT({fn LEFT(T1."ACCT_NR",4)},' _ ')},case when T2."DEPARTMENT" = ' ' then ' 00 ' else T2."DEPARTMENT" end )} else T1."ACCT_NR" end end end "c1" , T1."LEDGER_ACCTS_NAME" "c2" , T1."TYPE_ACCTT" "c3"
  26. from "OPTIMA"."import"."ACCOUNT_INFO" T1, "OPTIMA"."import"."ACCT_DOC_KEY" T2
  27. where T1."ACCT_NR" = T2."ACCT_NO" and T1."CLIENT_DB" = T2."CLIENT_DB" and T1."TYPE_ACCTT" = '2'
  28. order by 1 asc