SQL extract string Year YYYY from a Date Time for SSRS

Experts I'm developing some SSRS reports for the office and I'm trying to feed a string parameter from my SSRS report @Year (i.e. '2010') into a MS SQL statement to get a resultset of records for i.e. “2010”. “Indate” is the datetime field I need to compare the string parameter data to to get a resultset of just invoices for example '2010'. What functions and syntax should I use? Can you help our here? Thanks in Advance.


SELECT     CustSelCode, ExtPrice, ORep, InDate
FROM         [07Fox]
WHERE     ????? What function and syntax here?
GetRdoneAsked:
Who is Participating?
 
lwadwellCommented:
If InDate has time components ...
InDate BETWEEN convert(datetime, '01-01-'+@Year) AND convert(datetime, '12-31-'+@Year+' 23:59:59')
0
 
lwadwellCommented:
convert(varchar, year(InDate)) = @Year

or better still

InDate BETWEEN convert(date, '01-01-'+@Year) AND convert(date, '12-31-'+@Year)
0
 
ValentinoVBI ConsultantCommented:
Another method to get the year out of your datetime is by using the DATEPART function:

WHERE DATEPART(InDate) = @Year

Open in new window

0
 
GetRdoneAuthor Commented:
Thanks for the help!
0
 
ValentinoVBI ConsultantCommented:
In case someone stumbles upon this PAQ and notices my previous reply, looks like something went wrong while pasting that code.  This is what it should have been:

WHERE DATEPART(year, InDate) = @Year 

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.