Answered by:
getting a record thet is between 2 dates

Question
-
User3837996 posted
het guys
my employer wants to have a form that gets you the expenses between 2 dates.
i have looked a lot on the internet but i couldn't find anything that could solve my problem.
because the problem is that the 2 dates only have a specified month and year and both are in a different field.
could you guys please help me?
Friday, May 31, 2013 4:05 AM
Answers
-
User143067745 posted
Try it:
select Fields
from TableName
where (select [MM/YYYY] = right(convert(varchar(10),Date_Field_In_TABLE,103),7))
between (select [MM/YYYY] = right(convert(varchar(10),StartDate,103),7)) and (select [MM/YYYY] = right(convert(varchar(10),ENDDATE,103),7))Note: StartDate , ENDDATE can have formate of dd/MM/yyyy or MM/yyyy doesn't matter.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, May 31, 2013 5:59 AM
All replies
-
User-1716253493 posted
SELECT * FROM YOURTABLE WHERE DATEFIELD BETWEEN @START AND @FINIST
Friday, May 31, 2013 4:19 AM -
User3837996 posted
that i know.
but how to be able to only need to specify year and month that come from 2 different date fields
Friday, May 31, 2013 5:23 AM -
User143067745 posted
Try it:
select Fields
from TableName
where (select [MM/YYYY] = right(convert(varchar(10),Date_Field_In_TABLE,103),7))
between (select [MM/YYYY] = right(convert(varchar(10),StartDate,103),7)) and (select [MM/YYYY] = right(convert(varchar(10),ENDDATE,103),7))Note: StartDate , ENDDATE can have formate of dd/MM/yyyy or MM/yyyy doesn't matter.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, May 31, 2013 5:59 AM -
User-1716253493 posted
where year(datefield)=@Year and Month(datefield )=@MonthFriday, May 31, 2013 6:14 AM -
User3837996 posted
thanks
Monday, June 3, 2013 5:10 AM