Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Converting a Numeric column to Date column in snowflake

I have a table with a column "VALUATION DATE NUM", which stores integer in ‘20210331’ format. I have another column in the same table "VALUATION DATE" which is in date format, however is blank for now. I want to use the "VALUATION DATE NUM" column to update "VALUATION DATE" column in date format.

Using the query "UPDATE SPRD_MGMT_INP_FUND_VALUES SET "VALUATION DATE" = TO_DATE("VALUATION DATE NUM",’YYYY/MM/DD’);" is giving an error "SQL compilation error: invalid type [TO_DATE(SPRD_MGMT_INP_FUND_VALUES."VALUATION DATE NUM", ‘YYYY/MM/DD’)] for parameter ‘TO_DATE’"
Please help

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Using spaces in column names is not a good practice. Do you need something like this?

update yourtable SET "VALUATION DATE" = TO_DATE( "VALUATION DATE NUM"::VARCHAR,'YYYYMMDD' ) where "VALUATION DATE" is NULL; 

Note: Because you said blank values I added the WHERE condition.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading