In SQL Server Management Studio, I am trying to reference a specific date and time, using a variable for the date, as shown below.
Declare @specified_date Date set @specified_date = '07-01-2013' Select * from etc Where CreatedDate > CONVERT(datetime, @specified_date & '00:00:00.000' )
This code is not working, and I am receiving this error:
The data types date and varchar are incompatible in the '&' operator.
The data being used has both a date and time code on it, and instead of changing multiple queries, I'd like to be able to just define the date once and have the variable carry it across. If anyone knows of a solution, that would be great.
You can use now() with default auto fill and current date and time for this. Later, you can extract the date part using date() function. Let us set the default value with some date.
Did you try this:
Declare @specified_date Date set @specified_date = '07-01-2013' Select * from etc Where CreatedDate > @specified_date
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With