Reputation: 30303
In SQL Server, for the data type datetime
, can I insert like "00-00-0000"
from the front end? It is giving an error. I want to insert "00-00-0000"
if the user did not enter anything.
Upvotes: 0
Views: 1479
Reputation:
00-00-0000
is not a date. If the user didn't enter anything, and that's ok, enter NULL
. If you really want to show it as 00-00-0000
on the client side, you can do so using COALESCE
, e.g.
DECLARE @d TABLE(d DATETIME);
INSERT @d SELECT '2011-01-01'
UNION ALL SELECT NULL;
SELECT COALESCE(
CONVERT(CHAR(10), d, 120), '0000-00-00')
FROM @d;
Upvotes: 2