I have a table with following columns:
Item, Unit_Price, List_price, Start_date, End_date, Int_ind.
In my query – I have to show Current month sale. (The difference between start and end date should be 15 or more days)
In another query – I have to show next month sale. (The difference between start and end date should be 15 or more days)
Scenario 1: ( Current Month Sale)
If start_date and end_date are in the same month (say May) then my query is:
SELECT [ITEM], [UNIT_PRICE], [LIST_PRICE], (round(List_price,1) - round(unit_price,1)) as savings, [START_DATE], [END_DATE], [INT_IND] FROM TBL where INT_IND = 'SP'
and DATEDIFF(Day, Start_Date, End_Date) >=15 and datepart(month,start_date) in (select DATEPART (month,getdate())) and datepart(year,start_date) in (select DATEPART (year,getdate())) order by start_date.
The above query works correctly.
Scenario 2: (Current Month sale)
If start date is 29th or 30th of previous month and end date is 15th of current month then what should be my query.
Scenario 3: (Next Month Sale)
If start date and end date are in next month, then my query would be like:
SELECT [ITEM], [UNIT_PRICE], [LIST_PRICE], (round(List_price,1) - round(unit_price,1)) as savings, [START_DATE], [END_DATE], [INT_IND]
FROM TBL where INT_IND = 'SP'
and DATEDIFF(Day, Start_Date, End_Date) >=15 and datepart(month,start_date) in (select DATEPART (month,getdate())+1) and datepart(year,start_date) in (select DATEPART (year,getdate())) order by start_date.
Scenario 4: (Next month Sale)
If start date is 29th or 30th of this month and end date is 15th of next month then what should be my query.
Scenario 5: (Next Month sale)
If start date is next month (say June 5th ) and end date is 3rd July then what should be my query.
I will appreciate, if I can get any help.
Item, Unit_Price, List_price, Start_date, End_date, Int_ind.
In my query – I have to show Current month sale. (The difference between start and end date should be 15 or more days)
In another query – I have to show next month sale. (The difference between start and end date should be 15 or more days)
Scenario 1: ( Current Month Sale)
If start_date and end_date are in the same month (say May) then my query is:
SELECT [ITEM], [UNIT_PRICE], [LIST_PRICE], (round(List_price,1) - round(unit_price,1)) as savings, [START_DATE], [END_DATE], [INT_IND] FROM TBL where INT_IND = 'SP'
and DATEDIFF(Day, Start_Date, End_Date) >=15 and datepart(month,start_date) in (select DATEPART (month,getdate())) and datepart(year,start_date) in (select DATEPART (year,getdate())) order by start_date.
The above query works correctly.
Scenario 2: (Current Month sale)
If start date is 29th or 30th of previous month and end date is 15th of current month then what should be my query.
Scenario 3: (Next Month Sale)
If start date and end date are in next month, then my query would be like:
SELECT [ITEM], [UNIT_PRICE], [LIST_PRICE], (round(List_price,1) - round(unit_price,1)) as savings, [START_DATE], [END_DATE], [INT_IND]
FROM TBL where INT_IND = 'SP'
and DATEDIFF(Day, Start_Date, End_Date) >=15 and datepart(month,start_date) in (select DATEPART (month,getdate())+1) and datepart(year,start_date) in (select DATEPART (year,getdate())) order by start_date.
Scenario 4: (Next month Sale)
If start date is 29th or 30th of this month and end date is 15th of next month then what should be my query.
Scenario 5: (Next Month sale)
If start date is next month (say June 5th ) and end date is 3rd July then what should be my query.
I will appreciate, if I can get any help.