usp_GetCountExportedImage.sql 3.6 KB
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