I am trying to pull all data where a sale date is >= to a certain datetime. When I execute my query I get an error of:
Msg 241, Level 16, State 1, Line 15
Conversion failed when converting date and/or time from character string.
What should I alter to get his query operational? Below is sample DDL
Declare @datetime datetime = GetDate(), @sql varchar(max) Create Table #dinonuggets ( saledate datetime ,item varchar(500) ) Insert Into #dinonuggets Values ('2016-03-30 12:02:00.000','chair') ,('2016-03-04 08:12:48.000','stove') ,('2016-03-07 09:37:39.000','washer') Set @sql = 'Select * FROM #dinonuggets WHERE saledate >= '+@datetime+' ' Print @sql Exec (@sql)
My expected output would be
03/30/2016 12:02:00.000 chair
as that is the only data that meets the criteria