Hey there,
Would someone be able to help me sort out a better sql statement than the one I currently have, basically I want to be able to select two dates, start date and end date.
this is my current sql statement, I know it's pretty ugly looking. Don't give me a hard time about it please.
SELECT COUNT(*) FROM Promotion WHERE ProductNo = '" & Product.ProductNo & "' AND ProductNo IN(SELECT ProductNo FROM Promotion WHERE ([StartDate] < #" & Format(StartDate, "MM/dd/yyyy HH:mm:ss") & "# AND [EndDate] > #" & Format(StartDate, "MM/dd/yyyy HH:mm:ss") & "#) OR ([StartDate] < #" & Format(EndDate, "MM/dd/yyyy HH:mm:ss") & "# AND [EndDate] > #" & Format(EndDate, "MM/dd/yyyy HH:mm:ss") & "#) OR ([StartDate] > #" & Format(StartDate, "MM/dd/yyyy HH:mm:ss") & "# AND [EndDate] < #" & Format(EndDate, "MM/dd/yyyy HH:mm:ss") & "#) OR (StartDate = #" & Format(StartDate, "MM/dd/yyyy HH:mm:ss") & "# OR EndDate = #" & Format(StartDate, "MM/dd/yyyy HH:mm:ss") & "#) OR (StartDate = #" & Format(EndDate, "MM/dd/yyyy HH:mm:ss") & "# OR EndDate = #" & Format(EndDate, "MM/dd/yyyy HH:mm:ss") & "#))
Thanks in advance
Would someone be able to help me sort out a better sql statement than the one I currently have, basically I want to be able to select two dates, start date and end date.
- I want to see if promotions already exists during the dates I have selected. there are several conditions, one
- the startdate could be between the two promotion dates that are already there
- the enddate could be between the two promotion dates that are already there
- the the startdate selected could be before the promotions startdate and the end date selected could be after the promotions end date.
- they could also be equal, etc
- I think you get the idea
this is my current sql statement, I know it's pretty ugly looking. Don't give me a hard time about it please.
SELECT COUNT(*) FROM Promotion WHERE ProductNo = '" & Product.ProductNo & "' AND ProductNo IN(SELECT ProductNo FROM Promotion WHERE ([StartDate] < #" & Format(StartDate, "MM/dd/yyyy HH:mm:ss") & "# AND [EndDate] > #" & Format(StartDate, "MM/dd/yyyy HH:mm:ss") & "#) OR ([StartDate] < #" & Format(EndDate, "MM/dd/yyyy HH:mm:ss") & "# AND [EndDate] > #" & Format(EndDate, "MM/dd/yyyy HH:mm:ss") & "#) OR ([StartDate] > #" & Format(StartDate, "MM/dd/yyyy HH:mm:ss") & "# AND [EndDate] < #" & Format(EndDate, "MM/dd/yyyy HH:mm:ss") & "#) OR (StartDate = #" & Format(StartDate, "MM/dd/yyyy HH:mm:ss") & "# OR EndDate = #" & Format(StartDate, "MM/dd/yyyy HH:mm:ss") & "#) OR (StartDate = #" & Format(EndDate, "MM/dd/yyyy HH:mm:ss") & "# OR EndDate = #" & Format(EndDate, "MM/dd/yyyy HH:mm:ss") & "#))
Thanks in advance