MrProgram
MrProgram

Reputation: 5242

Check if value is positive or negative

I am trying to write a query which checks if 2 amounts have the same sign (+ or -). Do you have a good solutions that can be used?

Something like: If SAMESIGN(value1, value2) then do something

Upvotes: 7

Views: 38427

Answers (2)

Robert
Robert

Reputation: 25753

Try to use sign function as below

case 
when sign(value1)=sign(value2) then 'the same sign'
else 'different sign'
end

Upvotes: 11

Giannis Paraskevopoulos
Giannis Paraskevopoulos

Reputation: 18411

CASE WHEN (value1 * value2) < 0 THEN 'DiffSign' ELSE 'SameSignOrOneIsZero' END

Upvotes: 14

Related Questions