Karl_Schuhmann
Karl_Schuhmann

Reputation: 1332

MSSQL WHERE Function for a Date-Object

I have a table with a column id(int) and a column HolidayDate(Date) and I want to get the holidays of a specific month in a list. I know how to do that in code when i got the list with all holidays.

But i want do get the filtered list from the Database(MSSQL Express 2010). Is there a way to filter on a Date-Object in a stored Procedure, when i give the stored procedure the year and the month

For example, this doesn't work:

SELECT        Id, HolidayDate
FROM            dbo.Holiday
WHERE        (HolidayDate= '*.11.2013')

(Because converting from *.11.2013 to Date-Object does not work)

... and this work:

SELECT        Id, HolidayDate
FROM            dbo.Holiday
WHERE        (HolidayDate= '22.11.2013')

I just dont want to load a complete list of all holidays and filtering them in my program

Upvotes: 0

Views: 63

Answers (1)

nabuchodonossor
nabuchodonossor

Reputation: 2060

this will get your holidays within a given month:

SELECT        Id, HolidayDate
FROM            dbo.Holiday
WHERE         year(holidaydate) = 2013 and month(HolidayDate) = 11

Upvotes: 6

Related Questions