ALTER PROCEDURE [dbo].[getContractExpiration]
(
@TenantID INT
,@CompanyID INT = null
,@ExpDays INT
)
AS
BEGIN
SELECT COM.Name as CompanyName,
C.NAME,
SC.ContractID,
SC.INSTALLATIONDATE,
SC.STARTDATE,
SC.ENDDATE
FROM
CONTRACT
C
INNER
JOIN SERVICECONTRACT SC ON SC.CONTRACTID = C.ID
INNER
JOIN COMPANY COM ON
COM.ID = C.CompanyID
WHERE
C.TENANTID =@TenantID
AND C.COMPANYID=ISNULL(@CompanyID, C.CompanyID)
AND SC.EndDate BETWEEN GETDATE() and GETDATE()+ @ExpDays
END