By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,696 Members | 1,486 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,696 IT Pros & Developers. It's quick & easy.

ISNULL Function and String Concatenation

P: n/a
Dear Group

Just wondered how I can avoid the CHAR(32) to be inserted if @String1 is NULL?

SET @String3 = ISNULL(@String1,'') + CHAR(32) + ISNULL(@String2,'')

Thanks very much for your expertise and efforts!

Best Regards,

Martin
Jul 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
SET @String3 = ISNULL(@String1 + CHAR(32),'') + ISNULL(@String2,'')

--
David Portas
SQL Server MVP
--
Jul 20 '05 #2

P: n/a
Try:

SET @String3 = ISNULL(@String1 + CHAR(32),'') + ISNULL(@String2,'')

Alternatively:

SET @String3 = ISNULL(@String1 + ' ','') + ISNULL(@String2,'')

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Martin" <th************@hotmail.com> wrote in message
news:72**************************@posting.google.c om...
Dear Group

Just wondered how I can avoid the CHAR(32) to be inserted if @String1 is
NULL?

SET @String3 = ISNULL(@String1,'') + CHAR(32) + ISNULL(@String2,'')

Thanks very much for your expertise and efforts!

Best Regards,

Martin

Jul 20 '05 #3

P: n/a
Thanks Guys!

I actually was thinking about this but didn't try as I was the opinion
that @String1 + CHAR(32) would be evaluated first and always result in
a space even if String1 is NULL. But it actually makes sense as NULL +
something always results in NULL and therefore the condition is true.

However, it doesn't work for a string of length zero only NULL
strings. Any ideas?

Have a nice day!

Martin

th************@hotmail.com (Martin) wrote in message news:<72**************************@posting.google. com>...
Dear Group

Just wondered how I can avoid the CHAR(32) to be inserted if @String1 is NULL?

SET @String3 = ISNULL(@String1,'') + CHAR(32) + ISNULL(@String2,'')

Thanks very much for your expertise and efforts!

Best Regards,

Martin

Jul 20 '05 #4

P: n/a
Anybody try the obvious?

SET @String3 = RTRIM(LTRIM(ISNULL(@String1,' ') + CHAR(32) +
ISNULL(@String2,' ')))

Danny

"Martin" <th************@hotmail.com> wrote in message
news:72**************************@posting.google.c om...
Thanks Guys!

I actually was thinking about this but didn't try as I was the opinion
that @String1 + CHAR(32) would be evaluated first and always result in
a space even if String1 is NULL. But it actually makes sense as NULL +
something always results in NULL and therefore the condition is true.

However, it doesn't work for a string of length zero only NULL
strings. Any ideas?

Have a nice day!

Martin

th************@hotmail.com (Martin) wrote in message
news:<72**************************@posting.google. com>...
Dear Group

Just wondered how I can avoid the CHAR(32) to be inserted if @String1 is
NULL?

SET @String3 = ISNULL(@String1,'') + CHAR(32) + ISNULL(@String2,'')

Thanks very much for your expertise and efforts!

Best Regards,

Martin

Jul 20 '05 #5

P: n/a
SET @String3 = ISNULL(NULLIF(@String1,'') + CHAR(32),'') +
ISNULL(@String2,'')

--
David Portas
SQL Server MVP
--
Jul 20 '05 #6

P: n/a
Thanks Guys! I appreciate your help!
Have a nice day!
Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.