Skip to content
Advertisement

Add a column and populate it with the queried values from another column

I have a column having dates in varchar format, I want to convert it, to date format, which I did through below query:

select to_date(EVENT_DT, 'YYYYMMDD') from demographic;

Now, I want to create a new column and populate the column with the values that I got from above query. I am not able to do it with alter table.

Any solutions?

Advertisement

Answer

Hope it works as @Mike Walton said

Alter table demographic add Converted_date date;       
 ----ms sql server
Update demographic set Converted_date = convert(date, EVENT_DT , 101);
 ---or using to_date
Update demographic set Converted_date = to_date(EVENT_DT, 'YYYYMMDD');
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement