usp_GetCountExportedImage.sql
3.6 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
50
51
52
53
54
55
56
57
58
59
USE [AIADatabaseV5]
GO
/****** Object: StoredProcedure [dbo].[usp_GetCountExportedImage] Script Date: 9/16/2019 10:39:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Developer: <Birendra Kumar>
-- Create date: <8/05/2018>
-- Application :AIAHTML5
-- Description: <Gets exported image count based on user id and License Id>
-- [dbo].[usp_GetCountExportedImage] 34148
-- =============================================
CREATE PROCEDURE [dbo].[usp_GetCountExportedImage]
-- Add the parameters for the stored procedure here
@LicenseId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
SET NOCOUNT ON;
DECLARE @CountExportedImage INT;
DECLARE @isExportImage bit;
SET @isExportImage=0;
Declare @ExptImageLimit int;
Declare @TempLicenseSubscription TABLE(
licenseId int,
validFrom datetime,
validTo datetime,
imageExportLimit int
)
INSERT INTO @TempLicenseSubscription
SELECT LicenseId, SubscriptionValidFrom, SubscriptionValidThrough,NoofImages
FROM LicenseSubscriptionDetail
WHERE Id IN (SELECT MAX(Id) FROM LicenseSubscriptionDetail WHERE LicenseId = @LicenseId)
select @CountExportedImage =count(LIED.LicenseId) from LicenseImageExportDetail as LIED
Join @TempLicenseSubscription as TLS on LIED.LicenseId=TLS.licenseId
Where LIED.ExportedDate >=TLS.validFrom
AND LIED.LicenseId=@LicenseId
--GROUP BY LIED.LicenseId
-- having count(LIED.LicenseId)<1--@ExptImageLimit
select @ExptImageLimit=imageExportLimit from @TempLicenseSubscription
if(@CountExportedImage<@ExptImageLimit)
Begin
Set @isExportImage=1;
End
Select @isExportImage as isExportImage,@CountExportedImage as CountExportedImage,@ExptImageLimit as ExptImageLimit ;
END
GO