dbo.GetDiscountDetails.StoredProcedure.sql
2.96 KB
USE [AIADatabaseV5]
GO
/****** Object: StoredProcedure [dbo].[GetDiscountDetails] Script Date: 02/06/2018 10:49:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- ====================================================
-- Author: Magic Software
-- Create date: 23-Dec-2009
-- Description: To get the details of all discounts
-- ====================================================
CREATE PROCEDURE [dbo].[GetDiscountDetails]
-- Add the parameters for the stored procedure here
@sDiscountCode VARCHAR(255) = '', @sStartDate VARCHAR(20) = '', @sEndDate VARCHAR(20) = ''
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @dtStartDate DATETIME, @dtEndDate DATETIME
-- convert the datatype of startdate & enddate parameter to datetime
SELECT @dtStartDate = CONVERT(DATETIME,@sStartDate)
SELECT @dtEndDate = DATEADD(ms,-3,DATEADD(DAY,1,CONVERT(DATETIME,@sEndDate)))
SELECT Id, DiscountCode, Percentage, CONVERT(VARCHAR(10),StartDate,101) as StartDate, CONVERT(VARCHAR(10),EndDate,101) as EndDate,
(CASE IsActive WHEN 1 THEN 'Active' ELSE 'Inactive' END) AS Status
FROM Discount WHERE StartDate >= (CASE WHEN LEN(@sStartDate) > 0 THEN @dtStartDate ELSE StartDate END)
AND EndDate <= (CASE WHEN LEN(@sEndDate) > 0 THEN @dtEndDate ELSE EndDate END)
AND DiscountCode = (CASE WHEN LEN(@sDiscountCode) > 0 THEN @sDiscountCode ELSE DiscountCode END) ORDER BY Status
END
GO