Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / SQL Server / ADP / February 2004

Tip: Looking for answers? Try searching our database.

Concatenating Fields With Possible Null Values

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robert Gruenloh - 26 Feb 2004 18:15 GMT
I'm having trouble in SQL Server with an ADP in
concatenating fields where a value may be null. For
example, creating a single name field from separate last
name, first name, middle initial fields, where the middle
initial may be null. In Access, I just used the "Nz"
function: Lastname + ", " + Firstname + " " + Nz
(Middleinitial). I can't find a way to do this in SQL
Server - the closest I can come is to reset a database
option on how concatenation of null fields is handled,
which appears to have implications for other activities.
Does anyone have any suggestions on how to do this?

Thanks, Robert Gruenloh
Kevin3NF - 26 Feb 2004 18:41 GMT
You are on the right track...

In your stored procedure (I assume you are using SPs):

Set Concat_Null_Yields_Null Off

Your code goes here

Set Concat_Null_Yields_Null On

Signature

Kevin Hill
President
3NF Consulting

www.3nf-inc.com/NewsGroups.htm

> I'm having trouble in SQL Server with an ADP in
> concatenating fields where a value may be null. For
[quoted text clipped - 9 lines]
>
> Thanks, Robert Gruenloh
Dan Goldman - 26 Feb 2004 21:12 GMT
The SQL equivalent of the Nz function is the isnull function:
Lastname + ', ' + Firstname + ' ' + isnull(Middleinitial,'')
(unlike nz, the 2nd argument is required)

> I'm having trouble in SQL Server with an ADP in
> concatenating fields where a value may be null. For
[quoted text clipped - 9 lines]
>
> Thanks, Robert Gruenloh
Chris Howarth - 26 Feb 2004 22:34 GMT
> The SQL equivalent of the Nz function is the isnull function:
> Lastname + ', ' + Firstname + ' ' + isnull(Middleinitial,'')
> (unlike nz, the 2nd argument is required)

To cater for all possiblities I would be inclined to us:

isnull(Lastname + ', ','') + isnull(Firstname + ' ','') +
isnull(Middleinitial,'')

Although if the Lastname and Firstname are ever Null then this would suggest
that something is wrong with the validation applied before inserting the
row.

Chris
- 26 Feb 2004 22:59 GMT
Chris -
Thanks for the input. I'm validating last and first names,
so I should be OK. But your suggestion will come in handy
somewhere else, I'm sure.
Thanks, Robert
>-----Original Message-----
>> The SQL equivalent of the Nz function is the isnull function:
[quoted text clipped - 13 lines]
>
>.
- 26 Feb 2004 22:54 GMT
Thanks, Dan - that did it!

>-----Original Message-----
>The SQL equivalent of the Nz function is the isnull function:
[quoted text clipped - 16 lines]
>
>.
 
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.