Link to home
Start Free TrialLog in
Avatar of Whah
Whah

asked on

Convert varchar(20) to a date

Hi All,

Totally new with MSSQL...I have to make a change to 1.3 million records. I need to change field2 which is a varchar(20), to a date field which should look like this mm/dd/yyyy.

I looked on different sites, but I'm not entirely sure "exactly" how to do this.

I've attached a file. Any help would be greatly appreciated.
sqlscreenshot.docx
SOLUTION
Avatar of Brian Crowe
Brian Crowe
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Whah
Whah

ASKER

Yes, I am getting errors. Not knowing how something is "mis-formatted" is part of my problem.

Thank you.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Whah

ASKER

Thank you BriCrowe.
ALTER myTable ADD filed2date DATETIME;

UPDATE myTable SET filed2date = CAST(filed2 as datetime);

ALTER myTable DROP COLUMN filed2;

ALTER myTable ADD filed2 DATETIME;

UPDATE myTable SET filed2 = filed2date;

ALTER myTable DROP COLUMN filed2date;