-
Notifications
You must be signed in to change notification settings - Fork 5
/
Circulation compaing day this year to one last year.sql
77 lines (37 loc) · 1.9 KB
/
Circulation compaing day this year to one last year.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
--This should be what you're asking. It is two queries, one for yesterday, and one for the previous year. I commented out the organization from the select, just in case you wanted a total number. If you want per organization you can uncomment those lines.
--Yesterday of the previous year
select
-- torg.name as TransactionBranchName,
day(th.TranClientDate) as 'Day',
count(distinct th.transactionid) as Total
from PolarisTransactions.Polaris.TransactionHeaders th WITH (NOLOCK)
left outer join PolarisTransactions.Polaris.TransactionDetails td (nolock) on (th.TransactionID = td.TransactionID)
inner join Polaris.Polaris.Organizations torg (nolock) on (th.OrganizationID = torg.OrganizationID)
where th.TransactionTypeID = 6002
and td.TransactionSubTypeID = 38
and th.TranClientDate between Dateadd(YEAR,-1,cast(getdate()-1 as date) )and Dateadd(YEAR,-1,cast(getdate() as date) )
and th.OrganizationID in (4,2,5,17,16,18,6,20,7,3,8,15,9,19,10,11,12,13,14)
Group by
-- torg.name,
day(th.TranClientDate)
Order by
-- torg.name,
day(th.TranClientDate)
--yesterday
select
-- torg.name as TransactionBranchName,
day(th.TranClientDate) as 'Day',
count(distinct th.transactionid) as Total
from PolarisTransactions.Polaris.TransactionHeaders th WITH (NOLOCK)
left outer join PolarisTransactions.Polaris.TransactionDetails td (nolock) on (th.TransactionID = td.TransactionID)
inner join Polaris.Polaris.Organizations torg (nolock) on (th.OrganizationID = torg.OrganizationID)
where th.TransactionTypeID = 6002
and td.TransactionSubTypeID = 38
and th.TranClientDate between cast(getdate()-1 as date) and cast(getdate() as date)
and th.OrganizationID in (4,2,5,17,16,18,6,20,7,3,8,15,9,19,10,11,12,13,14)
Group by
-- torg.name,
day(th.TranClientDate)
Order by
-- torg.name,
day(th.TranClientDate)