I am getting conversion error when running the below sql in store procedure becasue of some reason I can’t cast into varchar
Declare @sql varchar(100)
Declare @ddtime datetime
set @ddtime = '2012-02-03 22:14:50.057'
set @sql = 'select * from table1 where tdate='+@ddtime
exec(@sql)
You need to convert the
@ddtimeto avarcharsince you are including it in a string:or just have you
@ddtimeas avarcharinstead of adatetime.The
convert(varchar(25), @ddtime, 121)leaves your date in the same format that you initially set it as.How to format datetime & date in Sql Server