dbo.GetSiteLicenseUsageReport.StoredProcedure.sql
3.96 KB
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
USE [AIADatabaseV5]
GO
/****** Object: StoredProcedure [dbo].[GetSiteLicenseUsageReport] Script Date: 02/06/2018 10:49:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Magic Software>
-- Create date: <14-Jan-2011>
-- Description: <To get the list of Site License Usage Report>
-- =============================================
CREATE PROCEDURE [dbo].[GetSiteLicenseUsageReport]
-- Add the parameters for the stored procedure here
@sFromDate varchar(20), @sToDate varchar(20), @sAccoutNumber varchar(50)='', @iEditionId tinyint = 0
AS
BEGIN
IF 1=0 BEGIN
SET FMTONLY OFF
END
-- SET NOCOUNT ON added to prevent extra result sets from
SET NOCOUNT ON
DECLARE @dtFromDate DATETIME
DECLARE @dtToDate DATETIME
-- convert the datatype of fromdate & todate parameter to datetime
SELECT @dtFromDate = CONVERT(DATETIME,@sFromDate)
SELECT @dtToDate = DATEADD(ms,-3,DATEADD(DAY,1,CONVERT(DATETIME,@sToDate)))
SELECT UserLoginLog.AccountNumber, Edition.Title AS EditionTitle, UserLoginLog.ReferalUrl,
(SELECT License.InstitutionName FROM License WHERE License.AccountNumber = UserLoginLog.AccountNumber) as InstitutionName,
(SELECT CONVERT(VARCHAR,License.CreationDate,101) FROM License WHERE License.AccountNumber = UserLoginLog.AccountNumber) as LicenseCreationDate,
COUNT(DISTINCT UserLoginLog.LogDate) AS TotalLogins,
CONVERT(VARCHAR,MAX(UserLoginLog.LogDate),101) AS LastLogin FROM
UserLoginLog INNER JOIN Edition ON UserLoginLog.Edition = CAST(Edition.Id AS NVARCHAR)
WHERE UserLoginLog.FailureId IS NULL
AND UserLoginLog.LogDate BETWEEN @dtFromDate AND @dtToDate
AND UserLoginLog.AccountNumber = (CASE WHEN LEN(@sAccoutNumber) > 0 THEN @sAccoutNumber ELSE UserLoginLog.AccountNumber END)
AND Edition.IsActive = 1
AND Edition.Id = (CASE WHEN @iEditionId > 0 THEN @iEditionId ELSE Edition.Id END)
GROUP BY UserLoginLog.AccountNumber, Edition.Title, UserLoginLog.ReferalUrl
END
GO