469,632 Members | 1,750 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,632 developers. It's quick & easy.

ISNULL Function and String Concatenation

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
6 10803
SET @String3 = ISNULL(@String1 + CHAR(32),'') + ISNULL(@String2,'')

--
David Portas
SQL Server MVP
--
Jul 20 '05 #2
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
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
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
SET @String3 = ISNULL(NULLIF(@String1,'') + CHAR(32),'') +
ISNULL(@String2,'')

--
David Portas
SQL Server MVP
--
Jul 20 '05 #6
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.

Similar topics

5 posts views Thread by Jonas Galvez | last post: by
2 posts views Thread by Bob Cottis | last post: by
8 posts views Thread by NickName | last post: by
35 posts views Thread by michael.casey | last post: by
1 post views Thread by rw | last post: by
12 posts views Thread by Richard Lewis Haggard | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.