Help with simple IsNULL query syntax

What is wrong with this syntax?

I am trying to add a '' if the value of the field is NULL

SELECT  ISNULL (users.FirstNm, '') AS FirstNm + ' ' + ISNULL (users.MiddleNm, '') AS MiddleNm + ' ' ISNULL (users.LastNm, '') AS LastNm    AS fullname 
    FROM   dbo.Cases
           INNER JOIN Users ON Users.UserId = Cases.Signatoryid
           LEFT JOIN Addresses AS c ON Users.Docstatusstat = c.Id

Open in new window


Getting an error saying there is a syntax error by the +  sign.
LVL 1
AleksAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Russ SuterCommented:
You cannot use aliases like that. You can only alias the entire column result. Try it like this:
SELECT  ISNULL (users.FirstNm, '') + ' ' + ISNULL (users.MiddleNm, '') + ' ' ISNULL (users.LastNm, '')  AS fullname 
    FROM   dbo.Cases
           INNER JOIN Users ON Users.UserId = Cases.Signatoryid
           LEFT JOIN Addresses AS c ON Users.Docstatusstat = c.Id

Open in new window

0
AleksAuthor Commented:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'users'.
0
Russ SuterCommented:
Actually, you can simplify a bit more by using the CONCAT() function.
SELECT  CONCAT(ISNULL (users.FirstNm, ''), ' ', ISNULL (users.MiddleNm, ''), ' ', ISNULL (users.LastNm, ''))  AS fullname 
    FROM   dbo.Cases
           INNER JOIN Users ON Users.UserId = Cases.Signatoryid
           LEFT JOIN Addresses AS c ON Users.Docstatusstat = c.Id

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AleksAuthor Commented:
This section option worked. The first one has a syntax error.
0
Russ SuterCommented:
Yep, I missed an extra '+' near the end of the concatenation. DOH! Actually, looking at it now, so did you. ;)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.