|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Using CASE to return positive or negative numbersnegative or vice versa. If QTY = 50 I want to return 50 when TRANS_TYPE = 'A' and -50 when TRANS_TYPE = 'B' If QTY = -10 I want to return -10 when TRANS_TYPE = 'A' and 10 when TRANS_TYPE = 'B' Psuedo code here: SELECT (CASE TRANS_TYPE WHEN 'A' THEN QTY WHEN 'B' THEN ??? (here is where I want to return negative if the number is positive or positive if the number is negative) END)as QTY, TRANS_TYPE, FROM TABLE1 SQL has a unary minus operator since the SQL-86 standards.
CASE trans_type WHEN 'A' THEN qty ELSE -qty END Thanks to all.
Is it appropriate to respond back to the newsgroup to say your issue is resolved or is that considered unnecessary noise. Show quote "--CELKO--" <jcelko***@earthlink.net> wrote in message news:1115933208.090797.57720@g44g2000cwa.googlegroups.com... > SQL has a unary minus operator since the SQL-86 standards. > > CASE trans_type WHEN 'A' THEN qty ELSE -qty END > It is a nice touch. Most of us wonder if the advice given is actually of
any value :) -- Show quote---------------------------------------------------------------------------- Louis Davidson - http://spaces.msn.com/members/drsql/ SQL Server MVP "Terri" <te***@cybernets.com> wrote in message news:d62fu6$ug7$1@reader2.nmix.net... > Thanks to all. > > Is it appropriate to respond back to the newsgroup to say your issue is > resolved or is that considered unnecessary noise. > > "--CELKO--" <jcelko***@earthlink.net> wrote in message > news:1115933208.090797.57720@g44g2000cwa.googlegroups.com... >> SQL has a unary minus operator since the SQL-86 standards. >> >> CASE trans_type WHEN 'A' THEN qty ELSE -qty END >> > > |
|||||||||||||||||||||||