Reputation: 45
I tried to find other questions that may have answered this but nothing really related to what I'm doing. I am making a view that has two joined tables in it. I need records to show up that only have the current year in the date, so when I make a report in Visual Studio, the user will only be able to see what has been done for the current year. I have experience in Access but am still trying to figure out SQL.
Upvotes: 3
Views: 9320
Reputation: 2194
You can use a "year" function on your datetime variable, like this:
SELECT * FROM TableName WHERE YEAR(date) = 2013
or if the current year needs to be dynamic:
SELECT * FROM TableName WHERE YEAR(date) = YEAR( getDate() )
Upvotes: 5
Reputation: 23228
Depending on what column you want to filter on, the query would look something like this:
SELECT *
FROM .... <your tables>
WHERE YEAR(YourColumn) = YEAR(getdate())
Upvotes: 0