0

hi
i have a table which contains a datetime type column.

i want to create a stored procedure that gets a surtain month and year as parameters and returns all the rows with the date column in the month and year range i sent as parameter.

for example if i send as parameter year 2009, and month 2,

i will get all rows with theese dates: '2.1.2009' , '2.4.2009' , '2.8.2009 ....
all the rows from the passed month and year.

i tryed to write a select statement like this:

select  * from Reports where UserId = @id and ReportDate like @month + '%' + @year + '%'

it doesnt work.
what am i duing wrong ?

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by emilio
0
select * from Reports where UserId = @id and datepart(mm,ReportDate) = @month and datepart(year,reportdate)= @year
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.