PC Review


Reply
Thread Tools Rate Thread

Combining 2 fields one may be null

 
 
Stever
Guest
Posts: n/a
 
      2nd Sep 2008
I created a seemingly simple query to combine 2 fields. It works as long as
there is information in both fields however if there is a null in either the
field is blank. Fields are of type NVARCHAR

This is what I would like to have happen.
Proj_No Alias_Number Proj_Alias_Number Currently the
results are
123 456 123 456
123 456
123 123
Blank
456 456
Blank


Here is what I have so far.
SELECT Proj_No + N' ' + Alias_Number AS Proj_Alias_Number,
FROM dbo.tblCivil_RecordScan


Thanks in advance!

Steve


 
Reply With Quote
 
 
 
 
bcap
Guest
Posts: n/a
 
      2nd Sep 2008
SELECT RTRIM(ISNULL(Proj_No + N' ','') + ISNULL(Alias_Number,'')) AS
Proj_Alias_Number FROM dbo.tblCivil_RecordScan

"Stever" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I created a seemingly simple query to combine 2 fields. It works as long as
>there is information in both fields however if there is a null in either
>the
> field is blank. Fields are of type NVARCHAR
>
> This is what I would like to have happen.
> Proj_No Alias_Number Proj_Alias_Number Currently the
> results are
> 123 456 123 456 123 456
> 123 123 Blank
> 456 456 Blank
>
>
> Here is what I have so far.
> SELECT Proj_No + N' ' + Alias_Number AS Proj_Alias_Number,
> FROM dbo.tblCivil_RecordScan
>
>
> Thanks in advance!
>
> Steve
>



 
Reply With Quote
 
Stever
Guest
Posts: n/a
 
      2nd Sep 2008
Thanks for the response. I tried your suggestion however I get the same
result. Is there another way to combine fields that tolerates Nulls?



"bcap" <(E-Mail Removed)> wrote in message
news:48bd7008$0$2503$(E-Mail Removed)...
> SELECT RTRIM(ISNULL(Proj_No + N' ','') + ISNULL(Alias_Number,'')) AS
> Proj_Alias_Number FROM dbo.tblCivil_RecordScan
>
> "Stever" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>I created a seemingly simple query to combine 2 fields. It works as long
>>as there is information in both fields however if there is a null in
>>either the
>> field is blank. Fields are of type NVARCHAR
>>
>> This is what I would like to have happen.
>> Proj_No Alias_Number Proj_Alias_Number Currently
>> the results are
>> 123 456 123 456 123 456
>> 123 123 Blank
>> 456 456 Blank
>>
>>
>> Here is what I have so far.
>> SELECT Proj_No + N' ' + Alias_Number AS Proj_Alias_Number,
>> FROM dbo.tblCivil_RecordScan
>>
>>
>> Thanks in advance!
>>
>> Steve
>>

>
>



 
Reply With Quote
 
Sylvain Lafontaine
Guest
Posts: n/a
 
      2nd Sep 2008
My first reaction would be to say that's impossible; unless you have made
some error while testing the piece of code given by Stever or that you are
not using an ADP project working against a SQL-Server.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)


"Stever" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks for the response. I tried your suggestion however I get the same
> result. Is there another way to combine fields that tolerates Nulls?
>
>
>
> "bcap" <(E-Mail Removed)> wrote in message
> news:48bd7008$0$2503$(E-Mail Removed)...
>> SELECT RTRIM(ISNULL(Proj_No + N' ','') + ISNULL(Alias_Number,'')) AS
>> Proj_Alias_Number FROM dbo.tblCivil_RecordScan
>>
>> "Stever" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>>I created a seemingly simple query to combine 2 fields. It works as long
>>>as there is information in both fields however if there is a null in
>>>either the
>>> field is blank. Fields are of type NVARCHAR
>>>
>>> This is what I would like to have happen.
>>> Proj_No Alias_Number Proj_Alias_Number Currently
>>> the results are
>>> 123 456 123 456 123 456
>>> 123 123 Blank
>>> 456 456 Blank
>>>
>>>
>>> Here is what I have so far.
>>> SELECT Proj_No + N' ' + Alias_Number AS Proj_Alias_Number,
>>> FROM dbo.tblCivil_RecordScan
>>>
>>>
>>> Thanks in advance!
>>>
>>> Steve
>>>

>>
>>

>
>



 
Reply With Quote
 
Stever
Guest
Posts: n/a
 
      2nd Sep 2008
So if I understand what you are saying.... It's impossible to combine them
if one if them is a null? If that's the case do you have an alternate
suggestion to achieve a similar result?

Thanks

Steve



"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:(E-Mail Removed)...
> My first reaction would be to say that's impossible; unless you have made
> some error while testing the piece of code given by Stever or that you are
> not using an ADP project working against a SQL-Server.
>
> --
> Sylvain Lafontaine, ing.
> MVP - Technologies Virtual-PC
> E-mail: sylvain aei ca (fill the blanks, no spam please)
>
>
> "Stever" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Thanks for the response. I tried your suggestion however I get the same
>> result. Is there another way to combine fields that tolerates Nulls?
>>
>>
>>
>> "bcap" <(E-Mail Removed)> wrote in message
>> news:48bd7008$0$2503$(E-Mail Removed)...
>>> SELECT RTRIM(ISNULL(Proj_No + N' ','') + ISNULL(Alias_Number,'')) AS
>>> Proj_Alias_Number FROM dbo.tblCivil_RecordScan
>>>
>>> "Stever" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>>I created a seemingly simple query to combine 2 fields. It works as long
>>>>as there is information in both fields however if there is a null in
>>>>either the
>>>> field is blank. Fields are of type NVARCHAR
>>>>
>>>> This is what I would like to have happen.
>>>> Proj_No Alias_Number Proj_Alias_Number Currently
>>>> the results are
>>>> 123 456 123 456 123 456
>>>> 123 123 Blank
>>>> 456 456 Blank
>>>>
>>>>
>>>> Here is what I have so far.
>>>> SELECT Proj_No + N' ' + Alias_Number AS Proj_Alias_Number,
>>>> FROM dbo.tblCivil_RecordScan
>>>>
>>>>
>>>> Thanks in advance!
>>>>
>>>> Steve
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Sylvain Lafontaine
Guest
Posts: n/a
 
      3rd Sep 2008
No: it's impossible that the piece of code given by Stever doesn't work as
expected.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)


"Stever" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> So if I understand what you are saying.... It's impossible to combine them
> if one if them is a null? If that's the case do you have an alternate
> suggestion to achieve a similar result?
>
> Thanks
>
> Steve
>
>
>
> "Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
> wrote in message news:(E-Mail Removed)...
>> My first reaction would be to say that's impossible; unless you have made
>> some error while testing the piece of code given by Stever or that you
>> are not using an ADP project working against a SQL-Server.
>>
>> --
>> Sylvain Lafontaine, ing.
>> MVP - Technologies Virtual-PC
>> E-mail: sylvain aei ca (fill the blanks, no spam please)
>>
>>
>> "Stever" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Thanks for the response. I tried your suggestion however I get the same
>>> result. Is there another way to combine fields that tolerates Nulls?
>>>
>>>
>>>
>>> "bcap" <(E-Mail Removed)> wrote in message
>>> news:48bd7008$0$2503$(E-Mail Removed)...
>>>> SELECT RTRIM(ISNULL(Proj_No + N' ','') + ISNULL(Alias_Number,'')) AS
>>>> Proj_Alias_Number FROM dbo.tblCivil_RecordScan
>>>>
>>>> "Stever" <(E-Mail Removed)> wrote in message
>>>> news:(E-Mail Removed)...
>>>>>I created a seemingly simple query to combine 2 fields. It works as
>>>>>long as there is information in both fields however if there is a null
>>>>>in either the
>>>>> field is blank. Fields are of type NVARCHAR
>>>>>
>>>>> This is what I would like to have happen.
>>>>> Proj_No Alias_Number Proj_Alias_Number Currently
>>>>> the results are
>>>>> 123 456 123 456 123 456
>>>>> 123 123 Blank
>>>>> 456 456 Blank
>>>>>
>>>>>
>>>>> Here is what I have so far.
>>>>> SELECT Proj_No + N' ' + Alias_Number AS Proj_Alias_Number,
>>>>> FROM dbo.tblCivil_RecordScan
>>>>>
>>>>>
>>>>> Thanks in advance!
>>>>>
>>>>> Steve
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Stever
Guest
Posts: n/a
 
      3rd Sep 2008
Hmm.... Strange... I tested the null problem by inserting a _ in a couple of
the records that had a null and they work fine after that so it must be
something with the null. I'm stumped. It seems so simple...

Steve



"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:(E-Mail Removed)...
> No: it's impossible that the piece of code given by Stever doesn't work as
> expected.
>
> --
> Sylvain Lafontaine, ing.
> MVP - Technologies Virtual-PC
> E-mail: sylvain aei ca (fill the blanks, no spam please)
>
>
> "Stever" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> So if I understand what you are saying.... It's impossible to combine
>> them if one if them is a null? If that's the case do you have an
>> alternate suggestion to achieve a similar result?
>>
>> Thanks
>>
>> Steve
>>
>>
>>
>> "Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
>> wrote in message news:(E-Mail Removed)...
>>> My first reaction would be to say that's impossible; unless you have
>>> made some error while testing the piece of code given by Stever or that
>>> you are not using an ADP project working against a SQL-Server.
>>>
>>> --
>>> Sylvain Lafontaine, ing.
>>> MVP - Technologies Virtual-PC
>>> E-mail: sylvain aei ca (fill the blanks, no spam please)
>>>
>>>
>>> "Stever" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> Thanks for the response. I tried your suggestion however I get the
>>>> same result. Is there another way to combine fields that tolerates
>>>> Nulls?
>>>>
>>>>
>>>>
>>>> "bcap" <(E-Mail Removed)> wrote in message
>>>> news:48bd7008$0$2503$(E-Mail Removed)...
>>>>> SELECT RTRIM(ISNULL(Proj_No + N' ','') + ISNULL(Alias_Number,'')) AS
>>>>> Proj_Alias_Number FROM dbo.tblCivil_RecordScan
>>>>>
>>>>> "Stever" <(E-Mail Removed)> wrote in message
>>>>> news:(E-Mail Removed)...
>>>>>>I created a seemingly simple query to combine 2 fields. It works as
>>>>>>long as there is information in both fields however if there is a null
>>>>>>in either the
>>>>>> field is blank. Fields are of type NVARCHAR
>>>>>>
>>>>>> This is what I would like to have happen.
>>>>>> Proj_No Alias_Number Proj_Alias_Number
>>>>>> Currently the results are
>>>>>> 123 456 123 456 123 456
>>>>>> 123 123 Blank
>>>>>> 456 456 Blank
>>>>>>
>>>>>>
>>>>>> Here is what I have so far.
>>>>>> SELECT Proj_No + N' ' + Alias_Number AS Proj_Alias_Number,
>>>>>> FROM dbo.tblCivil_RecordScan
>>>>>>
>>>>>>
>>>>>> Thanks in advance!
>>>>>>
>>>>>> Steve
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Sylvain Lafontaine
Guest
Posts: n/a
 
      3rd Sep 2008
Quick test:

select a, b, RTRIM(ISNULL(a + N' ','') + ISNULL(b,'')) AS r FROM (
select 1 as k, 'a' as a, 'b' as b
union all select 2, null, 'b'
union all select 3, 'a', null
) as q order by k

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)


"Stever" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hmm.... Strange... I tested the null problem by inserting a _ in a couple
> of the records that had a null and they work fine after that so it must be
> something with the null. I'm stumped. It seems so simple...
>
> Steve
>
>
>
> "Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
> wrote in message news:(E-Mail Removed)...
>> No: it's impossible that the piece of code given by Stever doesn't work
>> as expected.
>>
>> --
>> Sylvain Lafontaine, ing.
>> MVP - Technologies Virtual-PC
>> E-mail: sylvain aei ca (fill the blanks, no spam please)
>>
>>
>> "Stever" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> So if I understand what you are saying.... It's impossible to combine
>>> them if one if them is a null? If that's the case do you have an
>>> alternate suggestion to achieve a similar result?
>>>
>>> Thanks
>>>
>>> Steve
>>>
>>>
>>>
>>> "Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
>>> wrote in message news:(E-Mail Removed)...
>>>> My first reaction would be to say that's impossible; unless you have
>>>> made some error while testing the piece of code given by Stever or that
>>>> you are not using an ADP project working against a SQL-Server.
>>>>
>>>> --
>>>> Sylvain Lafontaine, ing.
>>>> MVP - Technologies Virtual-PC
>>>> E-mail: sylvain aei ca (fill the blanks, no spam please)
>>>>
>>>>
>>>> "Stever" <(E-Mail Removed)> wrote in message
>>>> news:(E-Mail Removed)...
>>>>> Thanks for the response. I tried your suggestion however I get the
>>>>> same result. Is there another way to combine fields that tolerates
>>>>> Nulls?
>>>>>
>>>>>
>>>>>
>>>>> "bcap" <(E-Mail Removed)> wrote in message
>>>>> news:48bd7008$0$2503$(E-Mail Removed)...
>>>>>> SELECT RTRIM(ISNULL(Proj_No + N' ','') + ISNULL(Alias_Number,'')) AS
>>>>>> Proj_Alias_Number FROM dbo.tblCivil_RecordScan
>>>>>>
>>>>>> "Stever" <(E-Mail Removed)> wrote in message
>>>>>> news:(E-Mail Removed)...
>>>>>>>I created a seemingly simple query to combine 2 fields. It works as
>>>>>>>long as there is information in both fields however if there is a
>>>>>>>null in either the
>>>>>>> field is blank. Fields are of type NVARCHAR
>>>>>>>
>>>>>>> This is what I would like to have happen.
>>>>>>> Proj_No Alias_Number Proj_Alias_Number Currently the results
>>>>>>> are
>>>>>>> 123 456 123 456 123 456
>>>>>>> 123 123 Blank
>>>>>>> 456 456 Blank
>>>>>>>
>>>>>>>
>>>>>>> Here is what I have so far.
>>>>>>> SELECT Proj_No + N' ' + Alias_Number AS Proj_Alias_Number,
>>>>>>> FROM dbo.tblCivil_RecordScan
>>>>>>>
>>>>>>>
>>>>>>> Thanks in advance!
>>>>>>>
>>>>>>> Steve
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
julien
Guest
Posts: n/a
 
      17th Sep 2008




CC
"Stever" <(E-Mail Removed)> a écrit dans le message de
news:(E-Mail Removed)...
>I created a seemingly simple query to combine 2 fields. It works as long as
>there is information in both fields however if there is a null in either
>the
> field is blank. Fields are of type NVARCHAR
>
> This is what I would like to have happen.
> Proj_No Alias_Number Proj_Alias_Number Currently the
> results are
> 123 456 123 456 123 456
> 123 123 Blank
> 456 456 Blank
>
>
> Here is what I have so far.
> SELECT Proj_No + N' ' + Alias_Number AS Proj_Alias_Number,
> FROM dbo.tblCivil_RecordScan
>
>
> Thanks in advance!
>
> Steve
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fill null fields from last non-null record - No update query pleas mattsmom Microsoft Access 2 2nd Apr 2008 01:56 PM
Null propogation - combining fields =?Utf-8?B?UG9wcGFjYXQ=?= Microsoft Access Queries 9 30th May 2006 02:57 PM
Null text box fields when group heading is null Richard Harison Microsoft Access Reports 8 1st Jul 2005 01:24 PM
Null Group Fields Not Equal to Null Non-Grouped Fields =?Utf-8?B?Q2hlcnlsIExhbW9uZHM=?= Microsoft Access Queries 3 29th Apr 2005 12:22 AM
Null result when combining null field with non-null field in ADP View Lauren Quantrell Microsoft Access Form Coding 8 17th Nov 2003 02:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:32 PM.