What is the best way of inserting a datetime value using dynamic sql

Posted by jaffa on Stack Overflow See other posts from Stack Overflow or by jaffa
Published on 2012-11-16T10:42:59Z Indexed on 2012/11/16 11:00 UTC
Read the original article Hit count: 163

Filed under:
|

What is the best way of inserting a datetime value using a dynamic sql string, whilst at the same time being able to handle the possibility of the value being null?

The current statement inserts into a table from a select statement built using a string. The datetime value is stored in a parameter and the parameter is used in the select.

Like so:

set @execsql = 'Insert into ( start_date )
SELECT ( ''' + CAST(start_date as VARCHAR) + ''' + ')'

© Stack Overflow or respective owner

Related posts about sql

Related posts about tsql