Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 cast default date field as varchar

Author  Topic 

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-01-20 : 09:47:46
My sql table has a date column which takes imported empty strings for that column and converts them to a default date. I want emptry strings in that field. Can i cast the date column for each update to force an empty string? if so, it would involve combining these two statements but i'm not sure how:

UPDATE evp_coc SET date= CAST (date AS VARCHAR) WHERE date ='1900-01-01 00:00:00.000'
UPDATE evp_coc SET date = '' WHERE date ='1900-01-01 00:00:00.000'

thanks

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-20 : 10:09:37
Assuming date column is a date/time data type (DATETIME, DATE etc.), you cannot do what you are trying to do,it will default to 1900-01-01. You can set it to NULL if the column is nullable and if NULL would be sufficient for your purposes.

Assuming that date column is of character type (which is not a good idea for various reasons), you can do it with one statement (the second statement in your post) as long as you know the exact format of the date string.
Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-01-20 : 10:30:31
Thanks. It's a date string which doesn't allow nulls. So we're stuck with it defaulting to funky dates.

Go to Top of Page
   

- Advertisement -