dbo.GetExportedImageDetails.StoredProcedure.sql
3.58 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
44
45
46
47
48
49
USE [AIADatabaseV5]
GO
/****** Object: StoredProcedure [dbo].[GetExportedImageDetails] Script Date: 2/1/2018 12:15:55 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: ADAM
-- Create date: 16 July 2013
-- Description: Get details of exported image based on parameters
-- =============================================
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetExportedImageDetails]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[GetExportedImageDetails]
GO
CREATE PROCEDURE [dbo].[GetExportedImageDetails]
@sStartDate varchar(20) = '', @sEndDate varchar(20) = '', @sAccoutNumber varchar(50)=''
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT
LID.LicenseId,
LID.ExportedDate,
LID.ImageName,
L.AccountNumber,
LID.OriginalFileName,
LID.Title,
LID.ModuleName,
(SELECT TOP(1) LSD.NoofImages FROM LicenseSubscriptionDetail LSD WHERE LSD.LicenseId = LID.LicenseId order by LSD.SubscriptionValidFrom desc) as ExportLimit,
USR.FirstName + ' '+ USR.LastName as UserName,
(SELECT COUNT(LID1.Id) FROM LicenseImageExportDetail LID1 WHERE LID1.LicenseId = LID.LicenseId group by LID1.LicenseId) as imageCount
FROM
LicenseImageExportDetail LID
LEFT JOIN License L ON LID.LicenseId =L.Id
INNER JOIN AIAUser USR ON LID.UserId = USR.Id
WHERE
((LEN(@sStartDate)=0) OR (LID.ExportedDate >= (CONVERT(DATETIME,@sStartDate)))) AND
((LEN(@sEndDate)=0) OR (LID.ExportedDate <= (DATEADD(ms,-3,DATEADD(DAY,1,CONVERT(DATETIME,@sEndDate)))))) AND
((LEN(@sAccoutNumber)=0) OR (AccountNumber LIKE '%'+@sAccoutNumber+'%'))
END
GO