-
Notifications
You must be signed in to change notification settings - Fork 5
/
Circulation statistical for a given date range by patron statistical class.sql
67 lines (60 loc) · 2.05 KB
/
Circulation statistical for a given date range by patron statistical class.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
DECLARE @CircTrans TABLE (
TransID INTEGER,
MatType INTEGER,
PSCCode INTEGER,
PatrBrn INTEGER,
ColCode INTEGER,
IsRenew INTEGER
);
INSERT INTO @CircTrans (TransID, MatType) SELECT TH.TransactionID,
TD.numValue
FROM PolarisTransactions.Polaris.TransactionDetails TD
JOIN PolarisTransactions.Polaris.TransactionHeaders TH
ON TH.TransactionID = TD.TransactionID WHERE TH.TransactionTypeID = 6001
AND TD.TransactionSubTypeID = 4
AND TH.TranClientDate >= @StartDate
AND TH.TranClientDate
;
UPDATE @CircTrans
SET PSCCode = TD.numValue
FROM PolarisTransactions.Polaris.TransactionDetails TD
WHERE TD.TransactionID = TransID
AND TD.TransactionSubTypeID = 7
;
UPDATE @CircTrans
SET PatrBrn = TD.numValue
FROM PolarisTransactions.Polaris.TransactionDetails TD
WHERE TD.TransactionID = TransID
AND TD.TransactionSubTypeID = 123
;
UPDATE @CircTrans
SET ColCode = TD.numValue
FROM PolarisTransactions.Polaris.TransactionDetails TD
WHERE TD.TransactionID = TransID
AND TD.TransactionSubTypeID = 61
;
UPDATE @CircTrans
SET IsRenew = TD.numValue
FROM PolarisTransactions.Polaris.TransactionDetails TD
WHERE TD.TransactionID = TransID
AND TD.TransactionSubTypeID = 124
;
SELECT COUNT(CT.TransID) AS 'Circulations',
O.[Name] AS 'Organization',
PSC.[Description] AS 'PatronStatCode',
M.[Description] AS 'MaterialType',
C.[Name] AS 'Collection',
CT.IsRenew AS 'IsRenewal'
FROM @CircTrans CT
LEFT JOIN Polaris.PatronStatClassCodes PSC
ON PSC.StatisticalClassID = CT.PSCCode
AND PSC.OrganizationID = CT.PatrBrn LEFT JOIN Polaris.MaterialTypes M
ON M.MaterialTypeID = CT.MatType
LEFT JOIN Polaris.Collections C
ON C.CollectionID = CT.ColCode
JOIN Polaris.Organizations O
ON O.OrganizationID = CT.PatrBrn
GROUP BY CT.PatrBrn, CT.PSCCode, PSC.[Description],
CT.MatType, CT.IsRenew, M.[Description],
C.[Name], O.[Name]
;