Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. Select count(*) as countForType,
  2. SUM(typeTable.amount) as totalForType,
  3. case
  4. when ( charindex('[', typeTable.source) > 0 and
  5. charindex(']', typeTable.source) > 0)
  6. then substring( typeTable.source,
  7. charindex('[', typeTable.source) +1,
  8. (charindex(']', typeTable.source) - 1) - charindex('[', typeTable.source))
  9. else null
  10. end
  11. as country
  12.  
  13. FROM theTypeTable typeTable (nolock)
  14. WHERE typeTable.startDate > @fromDate
  15. AND typeTable.startDate < @toDate
  16. AND typeTable.source like @source
  17. GROUP BY
  18. case
  19. when ( charindex('[', typeTable.source) > 0 and
  20. charindex(']', typeTable.source) > 0)
  21. then substring( typeTable.source,
  22. charindex('[', typeTable.source) +1,
  23. (charindex(']', typeTable.source) - 1) - charindex('[', typeTable.source))
  24. else null
  25. end
  26.  
  27. countForType totalForType country
  28. =========================================
  29. 590 82983909 en-US
  30. 689 93893829 de-CH
  31. 239 12738392 tr-TR
  32.  
  33. countForType totalForType country
  34. =========================================
  35. 590 82983909 NULL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement