[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

COALESCEand Non Null Values

scott

3/29/2007 4:19:00 PM

I use the below concatenation of the first, last name, middle initial and
suffix.using the COALESCE function. It works fine and renders the middle
initial and and a period if it the userMI field contains a letter or leaves
a space if the middle initial is null. The problem I've noticed is when the
middle initial field called userMI is not null, but is empty, my COALESCE
statement will insert the period and a space.

I posted an example below. Tim Brock's userMI field is blank. It doesn't
contain an empty space and has no length, but it isn't null. Therefore,
COALESCE thinks the empty field needs the period.

Is there a better way to evaluate the userMI field and only render the
userMI value with the period only if there is a "letter" in the field?

CODE ************
SELECT userLast, userFirst, userMI,

u.userFirst + COALESCE (' ' + u.userMI + '. ', ' ') + u.userLast + COALESCE
(' ' + u.userSuffix + '', '') AS FullName

FROM users u



EXAMPLE ***************

userLast userFirst userMI FullName
----------------------------------------------------------------
Smith John Q John Q. Smith
Jones Mike NULL Mike Jones
Brock Tim {blank} Tim . Brock




7 Answers

Tom Cooper

3/29/2007 4:29:00 PM

0

You can use the NullIf function to treat blanks and the empty string as
NULLs, like
SELECT userLast, userFirst, userMI,

u.userFirst + COALESCE (' ' + NullIF(u.userMI, '') + '. ', ' ') + u.userLast
+ COALESCE
(' ' + u.userSuffix + '', '') AS FullName

FROM users u

Tom

"scott" <sbailey@mileslumber.com> wrote in message
news:%23WAuG4hcHHA.4864@TK2MSFTNGP05.phx.gbl...
>I use the below concatenation of the first, last name, middle initial and
>suffix.using the COALESCE function. It works fine and renders the middle
>initial and and a period if it the userMI field contains a letter or leaves
>a space if the middle initial is null. The problem I've noticed is when the
>middle initial field called userMI is not null, but is empty, my COALESCE
>statement will insert the period and a space.
>
> I posted an example below. Tim Brock's userMI field is blank. It doesn't
> contain an empty space and has no length, but it isn't null. Therefore,
> COALESCE thinks the empty field needs the period.
>
> Is there a better way to evaluate the userMI field and only render the
> userMI value with the period only if there is a "letter" in the field?
>
> CODE ************
> SELECT userLast, userFirst, userMI,
>
> u.userFirst + COALESCE (' ' + u.userMI + '. ', ' ') + u.userLast +
> COALESCE (' ' + u.userSuffix + '', '') AS FullName
>
> FROM users u
>
>
>
> EXAMPLE ***************
>
> userLast userFirst userMI FullName
> ----------------------------------------------------------------
> Smith John Q John Q. Smith
> Jones Mike NULL Mike Jones
> Brock Tim {blank} Tim . Brock
>
>
>
>


frndthdevl@aol.com

12/9/2011 5:24:00 AM

0

When my Mom ws going through her 14 days or so hospice journey to the
next stage last June, I think my past tripping expeiences helped.
especially when in her courtyard was a fountain and ripple played over
and over in my head and on my iphone walking in the 100 plus temps and
in the ultra cool temps the hospice saints worked. It froze my tears
to my face.

This song helped too

making it out to mommas house

http://www.youtube.com/watch?v=S...

mr.rapidan

12/9/2011 5:42:00 AM

0

On Friday, December 9, 2011 12:24:20 AM UTC-5, frndthdevl wrote:
> When my Mom ws going through her 14 days or so hospice journey to the
> next stage last June, I think my past tripping expeiences helped.
> especially when in her courtyard was a fountain and ripple played over
> and over in my head and on my iphone walking in the 100 plus temps and
> in the ultra cool temps the hospice saints worked. It froze my tears
> to my face.
>
> This song helped too
>
> making it out to mommas house
>
> http://www.youtube.com/watch?v=S...

I prefer contemplating my psychological courage under the influence of mind-bending substances in the context of hypothetical death.

I'm very sorry about your mom.

But this is a new wrinkle - dealing with the death of a loved one in extreme temporal proximity - much different than dealing with your own, future death, even if the good doctor has circled a date on the calendar. After all, maybe they're wrong, etc.

I am not strong enough, I don't think, to deal with processing a close loved one's death in the circumstances under discussion. I mean, one would muddle through, but the journey would probably be rough.

frndthdevl@aol.com

12/9/2011 6:09:00 AM

0

On Dec 8, 9:41 pm, "dr.narcolepsy" <jmi...@gmail.com> wrote:
> I am not strong enough, I don't think, to deal with processing a close loved one's death

I guesss that is the worst thing about getting old. The freuquency in
which the Grim Reaper intrudes grows. I still remember the first
time(only time thankfully) a high school friend was killed by a drunk
driver. Getting the news returning to town from Disneyland in the
back seat of the Dodge Monaco station wagon, on the am radio, yeah
Tucson was still small enough the name of the victims still made the
radio. "dad, can you turn that up?" yeah its all come backing to me
now. But when my best friend who I had last seen at Red Rocks 1982
(He's Gone) died a few months after I had last seen him,shit, perhaps
29 years tongiht. falling off a pole in Glenwood Springs working as a
lineman after hours. It was a true time of aging. When a parent goes
it is all affirming, all down hill from there.,as those who have
experienced that around here will attest. One can only say it could
have been worse, i could have been younger. ro it could have been a
child. God bless Mr . fortenberry.



http://www.youtube.com/watch?v=3A-3S7P3Hik&featu...

mr.rapidan

12/9/2011 6:28:00 AM

0

On Friday, December 9, 2011 1:08:30 AM UTC-5, frndthdevl wrote:
> child. God bless Mr . fortenberry.

That's why I always cut Ken slack. There are no rules for how to process a child's death.

band beyond description

12/9/2011 8:32:00 AM

0

On 2011-12-09 12:27:35 +0600, "dr.narcolepsy" <jminpa@gmail.com> said:

> On Friday, December 9, 2011 1:08:30 AM UTC-5, frndthdevl wrote:
>> child. God bless Mr . fortenberry.
>
> That's why I always cut Ken slack. There are no rules for how to
> process a child's death.


at least someone has a bit of class in the vortex that is and surrounds Ken.
--
Peace,
Steve

john

12/9/2011 1:49:00 PM

0

On Dec 9, 1:08 am, frndthdevl <frndthd...@aol.com> wrote:

>
> I guesss that is the worst thing about getting old. The  freuquency in
> which the Grim Reaper intrudes grows.

"It may seem strange, yet who would change life's course to slower
speeding,
When one by one, our friends have gone, and left our bosoms bleeding?"

from "The River of Life", Thomas Campbell:

http://www.bartleby.com/10...