We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

SQL Query Results to new field based on criteria

ftarvin
ftarvin asked
on
Medium Priority
266 Views
Last Modified: 2012-05-07
select d as dog, b as boy, 1 as [positive], 1 as [negative]
 where x

so in this example the result in positive and negative would be the same.

I need to add logic to query so that if query result is positive number then result will only show up in [positive] else if amount is negative it will only show up in new [negative] field in result set.
Comment
Watch Question

Chief Technology Officer
CERTIFIED EXPERT
Most Valuable Expert 2011
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Kevin CrossChief Technology Officer
CERTIFIED EXPERT
Most Valuable Expert 2011

Commented:
For MySQL you can also use the IF construct:
SELECT IF(x>=0,x,NULL) AS [positive]

Author

Commented:
worked like a charm!

Thanks for the quick info.
Kevin CrossChief Technology Officer
CERTIFIED EXPERT
Most Valuable Expert 2011

Commented:
ftarvin,

You are most welcome.

Happy coding!

Best regards,
Kevin

Author

Commented:
both experts provided same solution at the same time... split points?
Kevin CrossChief Technology Officer
CERTIFIED EXPERT
Most Valuable Expert 2011

Commented:
Definitely appropriate. :)

Author

Commented:
Thanks again boyz.. funny thing is I had tried that but missed a #$% comma from previous select field and kept thinking it was an issue with my case expression! sloppy!

Speak to you soon Hall of Famer's !
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.