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 ?

select * from Reports where UserId = @id and datepart(mm,ReportDate) = @month and datepart(year,reportdate)= @year

ok.
thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.