forked from GMILCS/Polaris-TSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Checkouts in the last month based upon patron city's code.sql
49 lines (25 loc) · 1.39 KB
/
Checkouts in the last month based upon patron city's code.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
SELECT psc.description, COUNT(*) [Quantity]
FROM PolarisTransactions.Polaris.TransactionHeaders th WITH (NOLOCK)
JOIN PolarisTransactions.Polaris.TransactionTypes tt WITH (NOLOCK)
ON th.TransactionTypeID = tt.TransactionTypeID
JOIN PolarisTransactions.Polaris.TransactionDetails td WITH (NOLOCK)
ON th.TransactionID = td.TransactionID
AND td.TransactionSubTypeID = 6
JOIN PolarisTransactions.Polaris.TransactionSubTypes sub WITH (NOLOCK)
ON td.TransactionSubTypeID = sub.TransactionSubTypeID
JOIN Polaris.Polaris.PatronRegistration pr WITH (NOLOCK)
ON td.numValue = pr.PatronID
JOIN Polaris.Polaris.PatronStatClassCodes psc WITH (NOLOCK)
ON pr.StatisticalClassID = psc.StatisticalClassID
JOIN PolarisTransactions.Polaris.TransactionDetails tdMat WITH (NOLOCK)
ON tdMat.TransactionID = th.TransactionID
AND tdMat.TransactionSubTypeID = 4
JOIN PolarisTransactions.Polaris.TransactionSubTypes subMat WITH (NOLOCK)
ON tdMat.TransactionSubTypeID = subMat.TransactionSubTypeID
JOIN Polaris.Polaris.MaterialTypes mt WITH (NOLOCK)
on tdMat.numValue = mt.MaterialTypeID
WHERE th.TransactionTypeID IN (6001)
AND MONTH(TransactionDate) = MONTH(DateAdd(Month,-1,GETDATE()))
AND YEAR(TransactionDate) = YEAR(DATEADD(Month,-1,GETDATE()))
GROUP BY psc.Description
ORDER BY psc.Description