Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Coalesce Help

Author  Topic 

h2sut
Starting Member

40 Posts

Posted - 2008-05-14 : 15:56:18
How would i use a coalesece on this function to get null. if i use coalesce(xxxxx,0). If there is nothing in there it returns a blank space but i need to put null in there

cast([DPVisionPlan] as nvarchar(255)) [DPVisionPlan],

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-14 : 16:00:35
You wouldn't use COALESCE as that functions is used to replace NULL values with something else. You want the reverse. Try REPLACE function instead.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

h2sut
Starting Member

40 Posts

Posted - 2008-05-14 : 16:04:29
I want to use the coalese(xxxx,0) but not sure how it goes in
cast([DPVisionPlan] as nvarchar(255)) [DPVisionPlan],
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-14 : 16:08:28
You can't use COALESCE as it does the opposite of what you want.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-05-14 : 16:58:24
NULLIF() maybe?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-05-14 : 17:27:37
WHERE Col IS NULL



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-14 : 23:38:43
quote:
Originally posted by h2sut

How would i use a coalesece on this function to get null. if i use coalesce(xxxxx,0). If there is nothing in there it returns a blank space but i need to put null in there

cast([DPVisionPlan] as nvarchar(255)) [DPVisionPlan],


use NULLIF

NULLIF(cast([DPVisionPlan] as nvarchar(255)),' ') AS [DPVisionPlan],
Go to Top of Page

h2sut
Starting Member

40 Posts

Posted - 2008-05-15 : 12:09:14
Hello all the Nullif worked. Many thanks to all who help. ttyl
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-05-15 : 12:17:22
my Bad

But use ANSI code...is CASE ANSI?

CASE WHEN Col = ' ' Then null ELSE Col END

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

jdaman
Constraint Violating Yak Guru

354 Posts

Posted - 2008-05-15 : 12:36:56
quote:
Originally posted by X002548

if you say so h2slut



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam







Was that typo intentional?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-05-15 : 12:46:06
But thinking about it

Why not change the table def, make it null, and put a constraint so that it can't be space?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -