Date conversion error on UPDATE command
I have a stored procedure that is throwing an error on an UPDATE command here are the pertinent lines of code.
DECLARE @submitDate1 DATETIME;
SET @submitDate1 = GETDATE()
SET @sql = 'UPDATE ' + @currTable + ' SET [lang_String] = ''' + @lang_String + ''', [date_Changed] = ''' + @submitDate1 + ''', [prev_LangString] = ''' + @prev_LangString + ''', [needsTranslation] = ''' + @needsTranslation + ''' WHERE [ID] = ' + CAST(@ID as nvarchar(10)) + '; '
EXEC(@sql)
开发者_高级运维
Here is the error... Conversion failed when converting date and/or time from character string.
You have to convert the date into a string before concatenating it to the other strings:
... = ''' + convert(varchar(20), @submitDate1) + ''', [...
use
convert(varchar,@submitDate1)
at the place where you have used @submitDate1
variable.
SQL does not do implicit conversion from date to string!
精彩评论