Hi,
I am trying to dynamically build sql statement for a search form in a stored procedure.
All seems to be going well until dates are entered.
I have tried everything I can think of but keep getting error messages about converting strings to dates.
When I run the select statement below;
storedproc
@myDate datetime
as
select * from table where date > @myDate
return
and enter the date 10/02/03 (uk style)then all is ok.
But when I do the following
storedproc
@myDate datetime
as
declare @myStr varchar(500)
set @myStr = 'select * from thetable where thedate > ' + @myDate
exec (@myStr)
...things go wrong.
I have tried convert and cast, but obviously I am doing something wrong.
ps The reason for doing it this way is because there are other conditions that have to be met, the date is just one part and the code above is a snippet of the actual thing which does works - except for the dates.
Any ideas,anyone?
I am trying to dynamically build sql statement for a search form in a stored procedure.
All seems to be going well until dates are entered.
I have tried everything I can think of but keep getting error messages about converting strings to dates.
When I run the select statement below;
storedproc
@myDate datetime
as
select * from table where date > @myDate
return
and enter the date 10/02/03 (uk style)then all is ok.
But when I do the following
storedproc
@myDate datetime
as
declare @myStr varchar(500)
set @myStr = 'select * from thetable where thedate > ' + @myDate
exec (@myStr)
...things go wrong.
I have tried convert and cast, but obviously I am doing something wrong.
ps The reason for doing it this way is because there are other conditions that have to be met, the date is just one part and the code above is a snippet of the actual thing which does works - except for the dates.
Any ideas,anyone?