Monday, February 21, 2011

Problem setting a computed-column

I am trying to set this col but I get an error:

FirstName + (CASE WHEN LEN(FirstName + LastName) > 0 THEN ' ' ELSE '') + LastName
From stackoverflow
  • FirstName + (CASE WHEN LEN(FirstName + LastName) > 0 THEN ' ' ELSE '' end) + LastName
    

    missing the end

    Wahid Bitar : But what if last name length was 0 ?
    cmsjr : I was just addressing the OP's syntax problem, not his approach.
  • You should close CASE with END and also, to my opinion, the following value will be better:

    FirstName + (CASE WHEN LEN(FirstName) > 0 AND LEN(LastName) > 0 THEN ' ' ELSE '' END) + LastName
    
    Shimmy : Good point about counting the chars and sum them vs. concatenating strings which cost more performance.

0 comments:

Post a Comment