Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

SQL Server string concatenation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David - 24 Mar 2008 11:56 GMT
Hi all,

I have a small problem...

I need to do string concatenation in sql server...

i.e.

select field1 + field2 + field3 as JoinedField from table

This works fine IF all the fields have content, but if one of them is null,
then the whole JoinedField is null.

Any idea on how I can fix it? I want the joined value as though the null was
just an empty string.

Thanks.

Signature

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available

Just Me - 24 Mar 2008 12:12 GMT
Yeah

IsNull( field1, WhatYouWantGoesHere )

> Hi all,
>
[quoted text clipped - 13 lines]
>
> Thanks.
David - 24 Mar 2008 12:43 GMT
Cool, thank you. That works great...
Signature

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available

> Yeah
>
[quoted text clipped - 17 lines]
>>
>> Thanks.
Cowboy (Gregory A. Beamer) - 24 Mar 2008 14:01 GMT
select
   CASE WHEN field1 is null then ''
   ELSE field1 END
   +
   CASE WHEN field2 is null then ''
   ELSE field2 END
   +
   CASE WHEN field3 is null then ''
   ELSE field3 END  AS JoinedField

Signature

Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************

| Think outside the box!

*************************************************
> Hi all,
>
[quoted text clipped - 13 lines]
>
> Thanks.
Paul Shapiro - 24 Mar 2008 19:24 GMT
And a 3rd version (all 3 would work fine):

Select Coalesce(field1, '') + coalesce(field2, '') etc.

> select
>    CASE WHEN field1 is null then ''
[quoted text clipped - 25 lines]
>>
>> Thanks.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.