Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use thedatabase;
- declare @fromDate datetime = '2016-02-01 00:00:00.000';
- declare @toDate datetime = '2016-02-02 23:59:59.999';
- declare @source varchar(15) = 'server001';
- DECLARE @countForType bigint;
- DECLARE @totalForType decimal(30,8);
- DECLARE @country varchar(10);
- SELECT @countForType = count(*),
- @totalForType = SUM(typeTable.amount),
- @country =
- case
- when (charindex('[', typeTable.source) > 0 and charindex(']', typeTable.source) > 0)
- then substring(typeTable.source, charindex('[', typeTable.source) +1, (charindex(']', typeTable.source) - 1) - charindex('[', typeTable.source))
- else null
- end
- FROM theTypeTable typeTable (nolock)
- WHERE typeTable.startDate > @fromDate
- AND typeTable.startDate < @toDate
- AND typeTable.source like @source
- GROUP BY typeTable.source; -- i believe the issue may be here -- source is the entire string 'server001[en-US]'. I need to group and provide stats per country, which is a substring of source.
- --Print report:
- PRINT 'countForType: ' + CAST(@countForType AS VARCHAR);
- PRINT 'totalForType: ' + CAST(@totalForType AS VARCHAR);
- --for each country, print the amounts/ percentages etc...
- PRINT 'country: ' + CAST (@country AS VARCHAR);
- countForType: 104
- totalForType: 110000.00000000
- country: en-US
- countForType: 55
- totalForType: 95000.00000000
- country: de-CH
- countForType: 25
- totalForType: 5000.00000000
- country: tr-TR
- countForType: 30
- totalForType: 10000.00000000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement