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
Microsoft SQL Server

Avatar of undefined
Last Comment
Alpesh Patel

8/22/2022 - Mon
SOLUTION
Brian Crowe

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Whah

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

Thank you.
ASKER CERTIFIED SOLUTION
Brian Crowe

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Whah

ASKER
Thank you BriCrowe.
Alpesh Patel

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;
Your help has saved me hundreds of hours of internet surfing.
fblack61