IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Re: Another SQL Puzzle
Well the have given their answers. One requires a functional answer, the decode answer the easiest solution if your using Oracle.. But if your using SQL server this simple SQL statement will do.

(SELECT column_A, 1 AS bar
FROM TBL
WHERE column_A > 0)
UNION ALL
(SELECT column_A, 0 AS bar
FROM TBL
WHERE column_A = 0)
Taki Cuevas
New hmm - decode won't work afterall
upon rereading the puzzle, the decode solution wouldn't work. The requirement is > 0 turns into 1, which implies <= 0 turns to 0. The decode solution would have turned anything <> 0 into 1. It'll work if the data can only contain non-negative values, but we probably shouldn't make that assumption even though the sample doesn't include negative values.

Based on that, your solution would work with a minor change of <= 0 in the 2nd select's where clause.

Also welcome to the group! How'd you find us?
Darrell Spice, Jr.                      [link|http://spiceware.org/gallery/ArtisticOverpass|Artistic Overpass]\n[link|http://www.spiceware.org/|SpiceWare] - We don't do Windows, it's too much of a chore
New Nope, no negative in my case
Life could be simpler if they only standardized an "iif" function.

SELECT iif(b > 0, 1, 0) AS result FROM foo

It has the parameters: iif([expression],[value if true],[value if false])



________________
oop.ismad.com
New It has been standardized.
It's called [link|http://z.iwethey.org/forums/render/content/show?contentid=208883|CASE].
     Simple SQL look-up turns out hairy - (tablizer) - (51)
         I awalys hated SQL based batch updates - (broomberg) - (12)
             Let's bring back FoxPro! - (tablizer) - (11)
                 Silly person you - (broomberg) - (10)
                     Preach! -NT - (drewk)
                     63.472% Disagree - (tablizer)
                     Real world example - (broomberg) - (7)
                         I am not sure what your point is - (tablizer) - (6)
                             It's been done already - (broomberg) - (5)
                                 Or PL/SQL, or TransactSQL, or... -NT - (admin) - (4)
                                     Nah - (broomberg) - (2)
                                         I didn't say they were the best. - (admin) - (1)
                                             I know. I do. - (broomberg)
                                     I find PL/SQL and Transact/SQL too verbose -NT - (tablizer)
         COALESCE - (drewk)
         Re: Simple SQL look-up turns out hairy - (JayMehaffey)
         Simpler SQL - (ChrisR) - (2)
             My 1999 book implies UPDATE....FROM is not standard -NT - (tablizer) - (1)
                 Probably so... - (ChrisR)
         And you're surprised because what? -NT - (pwhysall)
         Another SQL Puzzle - (tablizer) - (31)
             Re: Another SQL Puzzle - (ChrisR) - (25)
                 Hmmm. Standard? -NT - (tablizer) - (24)
                     No such thing in SQL world - dialects everywhere -NT - (tuberculosis) - (22)
                         Good point. Standard != Common_Implementation - (tablizer) - (21)
                             Lemme guess... - (ben_tilly) - (20)
                                 The best way to fix non-standard implementations.... - (ChrisR)
                                 I had a look. - (static) - (13)
                                     Fish in a barrel -NT - (ben_tilly)
                                     Please be more specific -NT - (tablizer) - (11)
                                         Horse corpse - meet Mr. Stick -NT - (broomberg) - (1)
                                             IOW, guilty until proven innocent. IranWeThey - (tablizer)
                                         Sorry, I've got real SQL work to do. -NT - (static) - (8)
                                             SQL sucks (as a relational language) - (tablizer) - (7)
                                                 Perhaps you need to get out of the design and... - (ChrisR) - (6)
                                                     Some convergence perhaps - (tablizer) - (5)
                                                         sounds like you would be happy doing MAS90 -NT - (boxley) - (2)
                                                             Wow. That's harsh. ;0) -NT - (mmoffitt) - (1)
                                                                 its straight forward, lucrative and he enjoys the language -NT - (boxley)
                                                         You are writing a language IN xBase? - (broomberg) - (1)
                                                             I am sort of pushing off parsing issues to something else -NT - (tablizer)
                                 WRONGO! - (tablizer) - (4)
                                     Re: WRONGO! - (JayMehaffey) - (3)
                                         Prefix != "procedural" - (tablizer) - (2)
                                             I wasn't talking aobut it's notation - (JayMehaffey) - (1)
                                                 Variables can be semantic "references", not necess. storage - (tablizer)
                     CASE is the ANSI/ISO-standard - (ChrisR)
             Easy if you have decode - (SpiceWare)
             Re: Another SQL Puzzle - (takicutie) - (3)
                 hmm - decode won't work afterall - (SpiceWare) - (2)
                     Nope, no negative in my case - (tablizer) - (1)
                         It has been standardized. - (ChrisR)

Boy, isn't that true about damn near any subject?
134 ms