October 1, 2015 at 3:37 am
Hi,
I have a date column (not datetime) in SQL Server and the dates are in the format yyyy-mm-dd
I need to replace the date values with zero's so it looks like 0000-00-00
I can currently get the current date in to the column like this:
UPDATE TestTable_1
set datecolumn = CONVERT(varchar(10), GETDATE(), 10)
But instead of GETDATE() I need to enter the zero's like this: 0000-00-00
How can I do this?
Thanks.
October 1, 2015 at 3:48 am
From what you're saying you want to replace all with 0s..
UPDATE TestTable_1
set datecolumn = '0000-00-00';
October 1, 2015 at 3:54 am
Tried that. I get the following error:
Conversion failed when converting date and/or time from character string.
October 1, 2015 at 4:21 am
You cant do 0000-00-00 in any date field, if thats what you need I suggest CHAR(10)
If you need it in a DATE datatype column the lowest value you can do is 0001-01-01 up to 9999-12-31
October 1, 2015 at 4:25 am
Ok thanks.
October 1, 2015 at 4:41 am
zedtec (10/1/2015)
Hi,I have a date column (not datetime) in SQL Server and the dates are in the format yyyy-mm-dd
I need to replace the date values with zero's so it looks like 0000-00-00
I can currently get the current date in to the column like this:
UPDATE TestTable_1
set datecolumn = CONVERT(varchar(10), GETDATE(), 10)
But instead of GETDATE() I need to enter the zero's like this: 0000-00-00
How can I do this?
Thanks.
This is what NULL is for.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
October 1, 2015 at 8:46 am
zedtec (10/1/2015)
Hi,I have a date column (not datetime) in SQL Server and the dates are in the format yyyy-mm-dd
I need to replace the date values with zero's so it looks like 0000-00-00
I can currently get the current date in to the column like this:
UPDATE TestTable_1
set datecolumn = CONVERT(varchar(10), GETDATE(), 10)
But instead of GETDATE() I need to enter the zero's like this: 0000-00-00
How can I do this?
Thanks.
This should only be done during display time. Store NULLs in the column where this needs to be done so that you don't end up with all of the problems associated with storing dates/times as a VARCHAR.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 1, 2015 at 8:51 am
Ok will do thanks.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply