Search code examples
datatablecopysnowflake-cloud-data-platform

How to copy another columns value to a new created value in SNOWFLAKE


I am trying to add values to a newly created column from another column in SNOWFLAKE database, could someone please help. I want values of OrderID column to be inserted in CompanyID

enter image description here


Solution

  • The table has to be updated:

    UPDATE tab
    SET CompanyID = OrderID
    -- WHERE CompanyID IS NULL;
    

    If the table is createad first time column CompanyID could be added inside CTAS:

    CREATE TABLE tab
    AS
    SELECT OrderID AS CompanyID, OrderID, CustomerName
    FROM db_soure_name.schema_name_table_name;