The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.
I'm writing a query where several columns are actually sub-queries whose final result is a number. In practice, many of these values will be zeroes, in which case I want to substitute in a null value for a "0" so the report looks a little cleaner (instead of having zeroes everywhere). This seems like it should be simple to do with DECODE:
DECODE(<big long sub-query>, 0, null)
The problem with this is that DECODE will return null if it doesn't find a match. You can provide a default value as an argument, but in my case, this would involve nesting the entire sub-query into the DECODE a second time:
DECODE(<big long sub-query>, 0, null, <big long sub-query>)
This seems tremendously inefficient. Is there a way to solve this without having to include the sub-query twice? I looked at CASE briefly but I still don't see how that would solve the root problem.
Thanks!
whuppins on
0
Posts
Deebaseron my way to work in a suit and a tieAhhhh...come on fucking guyRegistered Userregular
edited July 2009
create a temp/hash table and do it on the back end
UPDATE #table_name
SET column_name = null
FROM #table_num
WHERE column_name = 0
It's for work. I've been asked to implement a solution we received from a colleague at another company. The solution involves creating a view that will be referenced by a third-party piece of software. Because the data is ultimately going to be displayed in a 'non-native' environment, we have some limitations on how much we can do.
whuppins on
0
Deebaseron my way to work in a suit and a tieAhhhh...come on fucking guyRegistered Userregular
edited July 2009
ahhh that makes sense. Sorry my nerd skills are weaksauce. =(
CASE could work if you can shoehorn
(subquery) = 0
into the WHEN, but I dunno if that would even work as it would may require implicit conversion to get a null value.
Actually, I think I may have stumbled upon a solution (based on an earlier thread in this forum). I think I can just change DECODE to REPLACE in my original example and it will work. Not really the intended use of REPLACE, but I think it'll get the job done! Testing underway...
Posts
UPDATE #table_name
SET column_name = null
FROM #table_num
WHERE column_name = 0
SELECT * FROM #table_name
rinse and repeat for all the columns.
This is Oracle PL/SQL, by the way.
Aside from exporting the data and doing an excel find/replace I got nothing. Sorry =(
(Out of curiosity. Is this for work or school?)
CASE could work if you can shoehorn
(subquery) = 0
into the WHEN, but I dunno if that would even work as it would may require implicit conversion to get a null value.