سؤال

I have a store procedure. When this sp execute, I want to save start time and end time in my database. So, I use CURRENT_TIMESTAMP to get current time with millisecond. But, when I use a dynamic query to update my table like:

Set @query = 'Update Table1 set startTime='''+CURRENT_TIMESTAMP+''' where '+@Condition
EXEC(@query)

I got this error: Conversion failed when converting date and/or time from character string.

So, I change my code to:

Set @query = 'Update Table1 set startTime='''+CAST(CURRENT_TIMESTAMP as varchar(100))+''' where '+@Condition
EXEC(@query)

Now, it execute success but the result doesn't contain millisecond. How to save the result include millisecond?

هل كانت مفيدة؟

المحلول

In your first query, you get an error because you're trying to add a string to a date.

Try this

 set @query = 'Update Table1 set startTime=CURRENT_TIMESTAMP where ' + @condition
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top