Sintax error in update table

Answered Sintax error in update table

  • Monday, February 04, 2013 4:54 PM
     
      Has Code
    update dimcustomer set fullname=FirstName+case WHEN isnull(middlename) then "" else middlename END + LastName

    Sorry, it's one of these day...the query above returns me the error:

    The isnull function requires two arguments . Any suggestion? I'm going to find out the mistake but I got involved in four different sintax today...

All Replies

  • Monday, February 04, 2013 5:00 PM
     
     

    Hello,

    Revised sytax below

    update dimcustomer
    set fullname=FirstName+case WHEN isnull(middlename,'')  = ''
    Then ''

    else middlename  
    END + LastName

  • Monday, February 04, 2013 5:04 PM
     
     Answered Has Code

    Try:

    update dimcustomer set fullname=FirstName+case WHEN middlename IS NULL then '' else middlename END + LastName

    You could also shorten it by removing the case statement in this case with ISNULL.

    update dimcustomer set fullname=FirstName+ isnull(middlename,'') + LastName

    I'm not sure if you meant to leave spaces out of fullname or not so I have also omitted them.


    • Edited by Barry Marshall Monday, February 04, 2013 5:05 PM
    • Marked As Answer by DIEGOCTN Monday, February 04, 2013 5:10 PM
    •  
  • Monday, February 04, 2013 5:04 PM
     
     

    Try something like below:

    update dimcustomer set fullname=FirstName+case WHEN IsNull(middlename,'') = ''  then '' else middlename END


    Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

  • Monday, February 04, 2013 5:09 PM
     
     

    ISNULL() is TSQL, so you might look at using COALESCE which is ANSI SQL.

    UPDATE dimcustomer
    SET FullName = FirstName + COALSECE(' ' + MiddleName, '') + ' ' + LastName

    Other programming notes:

    I would reverse the naming convention to become NameFull, NameFirst, etc so that all the Name fields are ordered if you use some tool that examines the table structure and reports the field names in alphabetical order

    Verify you have spaces between the names.

    ISNULL http://msdn.microsoft.com/en-us/library/ms184325.aspx

    COALESCE http://msdn.microsoft.com/en-us/library/ms190349.aspx

    CASE WHEN http://msdn.microsoft.com/en-us/library/ms181765.aspx

  • Monday, February 04, 2013 5:11 PM
     
      Has Code

    Try -

    UPDATE dimcustomer 
    SET fullname=FirstName+' '+ISNULL(NULLIF(middlename,NULL),'')+' '+LastName


    Narsimha