Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am concatenating 2 fields in a st 1

Status
Not open for further replies.

sodakotahusker

Programmer
Mar 15, 2001
601
I am concatenating 2 fields in a stored procedure - for example

city + " " + state as citystate

if city is null - citystate comes back null even if state has a value. Is there an easy solution to this so I don't have to resort to the CASE block???

Thanks!!!
 
Try this...

SELECT LTRIM(ISNULL(firstnm,'') + ' ' + ISNULL(lastnm,'')) AS CITYSTATE
FROM mytable


LTRIM is used so that it will not give you a blank space when there's no city. ISNUll is used to check for null values and replace it with 0 space.

Andel
andelbarroga@hotmail.com
 
sorry, the example should be...

SELECT LTRIM(ISNULL(city,'') + ' ' + ISNULL(state,'')) AS CITYSTATE
FROM mytable


Andel
andelbarroga@hotmail.com
 
Andel,
Works like a champ!!!!!!!!!!!! Thank you very much!!!!
Don
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top