Question : Get Year from Date in SQL Statement

I am trying to return records from a database based on two criteria defined by the user.  The part I am having a problem with is getting only records for a specifc year based on the date in one of the table columns.

Here is my SQL statement:  "SELECT * FROM tblGame_Schedules WHERE Home_Team = '" & Me.dropdownlist1.selectedvalue & "' OR Visiting_Team = '" & Me.dropdownlist1.selectedvalue & "' AND Year(Game_Date) = '" & Me.dropdownlist2.selectedvalue & "' ORDER By Game_Date, Game_Time"

The column game_date contains a date value.
The values in Me.dropdownlist2 are 2007, 2008, 2009

The above sql statement returns all records and not only the records for the selected year.   I assume that I am doing something trying to get just the year from the game_date column.

Any help would be appreciated.



Answer : Get Year from Date in SQL Statement

You need paranthesis around your OR items (the teams i assume).


"SELECT * FROM tblGame_Schedules WHERE (Home_Team = '" & Me.dropdownlist1.selectedvalue & "' OR Visiting_Team = '" & Me.dropdownlist1.selectedvalue & "') AND Year(Game_Date) = '" & Me.dropdownlist2.selectedvalue & "' ORDER By Game_Date, Game_Time"
Random Solutions  
 
programming4us programming4us