CASE Syntax For Default values based on two columns

  • Hi Guys,

    Can anyone please point me in the right direction with syntax.

    I want to give a default for a column depending on two other columns.

    If the users don't enter the address I want to set a default address for each client.

    The two columns are client and address.

    I want to say if the address is null and client name = Client1 then set address = Address1.

    And is the address is not null, use the address that is there.

    Here is a code example:

    select

    case

    WHEN addr is NULL AND Name = 'Client1'

    then addr = 'Address1'

    else addr

    end

    from table

    I want to add a check constraint to achieve this but my syntax is wrong in the then part of the case.

    Thanks in advance

  • Hi Guys,

    Sorry I was being dumb.

    It will just be normal case syntax.

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

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