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.
Author |
Topic |
V.V.
Starting Member
32 Posts |
Posted - 2011-04-02 : 03:20:11
|
Hi guys,I have a table which contains NULL among other data. So, in this case I want to replace NULL with "-" and leave the others data intact. For that I used this:SELECT a,b,c,CASE WHEN d IS NULL THEN '-' ELSE (what I should put here to leave the others data intact?)END AS eFROM X.dbo.Table1L.E.: I think I found a solution after all. Instead script above I use:SELECT a,b,c,ISNULL(d,e)FROM X.dbo.Table1Is it ok with second solution or is a better one?Thanks. |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-04-02 : 05:20:05
|
SELECT a,b,c,CASEWHEN d IS NULL THEN '-'ELSE d END AS eFROM X.dbo.Table1or just coalesce(d,'-')In this case. Coalesce returns the first non-null value in the list.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
V.V.
Starting Member
32 Posts |
Posted - 2011-04-02 : 11:54:48
|
I used second method from my post, the one with ISNULL.Is ok guys or should I use something else?@nigelrivett, thanks for help. |
 |
|
jeffw8713
Aged Yak Warrior
819 Posts |
Posted - 2011-04-02 : 12:18:59
|
You should read up on the difference between ISNULL and COALESCE. They are similar, but it is where they are different that could cause you problems.In your scenario, either will do exactly the same thing. COALESCE is ANSI standard and allows for multiple parameters whereas ISNULL is not standard and only allows a single parameter.JeffJeff |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|