insert when null

  • Dear All,

    I am populating some new tables from old tables, after I did some re-structuring to the database.

    I have created a table with langID and langCode.

    I also created a temptable, with the data being captured from an old table. The fields that are the most relevant at the moment are lid, and fk_langid.

    In the old table, lid, has strings in it, for example en, fr, bg etc, and fk_langId will be the foreign key to the new table.

    Now my problem is that there are some lid's which do not exist in the new table, and as so I need to hardcode an id for them in the new table.

    So I was doing something like this:-

    update #tempTable

    SET fk_langid =

    (

    SELECT lid,

    CASE

    WHEN lid like '%sr%' THEN '1234'

    END

    FROM #tempTable

    )

    But I am getting an error:-

    Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

    Can you help me out on how I can update the fk_langid in the temptable

  • got it!

    update #tempTable

    SET fk_langid =

    (

    --SELECT lid,

    CASE

    WHEN lid like '%sr%' THEN '1234'

    END

    --FROM #tempTable

    )

    Thanks

  • Correct, you don't subquery inside the CASE.

    However, if you have NULLs, then you can IFNULL( field, default value)

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply