Reputation: 1779
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.
Upvotes: 1
Views: 302
Reputation: 11
use
convert(varchar,@submitDate1)
at the place where you have used @submitDate1
variable.
SQL does not do implicit conversion from date to string!
Upvotes: 1
Reputation: 700670
You have to convert the date into a string before concatenating it to the other strings:
... = ''' + convert(varchar(20), @submitDate1) + ''', [...
Upvotes: 4