Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 Convert positive number to a negative Rate Topic Display Mode Topic Options
Author
 Message
 Posted Tuesday, October 16, 2007 5:37 AM
 Old Hand Group: General Forum Members Last Login: Tuesday, April 29, 2014 6:47 AM Points: 319, Visits: 783
 Hi All,How can you convert a positive number into a negative. I have tried *-1 but this doesn't seem to work.Thanks
Post #411207
 Posted Tuesday, October 16, 2007 5:44 AM
 SSCrazy Group: General Forum Members Last Login: Tuesday, June 7, 2016 5:15 AM Points: 2,562, Visits: 2,643
 DECLARE @InitialNumber INTDECLARE @OutputNumber INTSET @InitialNumber = 9SET @OutputNumber = ( CASE WHEN @InitialNumber > 0 THEN -@InitialNumber ELSE @InitialNumber END )SELECT @InitialNumber AS Initial, @OutputNumber AS FinalWorks like a charm.... --Ramesh
Post #411212
 Posted Tuesday, October 16, 2007 7:09 AM
 SSCertifiable Group: General Forum Members Last Login: Today @ 9:48 AM Points: 7,842, Visits: 9,322
 * -1 should workwhat is the datatype and what makes you think it did not workbtwpreceding a column or variable with - will achieve the same, eg DECLARE @myvariable int SET @myvariable = 1 SELECT @myvariable,-@myvariable Far away is close at hand in the images of elsewhere.Anon.
Post #411267
 Posted Tuesday, October 16, 2007 7:17 AM
 SSCrazy Group: General Forum Members Last Login: Wednesday, November 23, 2016 7:41 AM Points: 2,777, Visits: 4,098
 David Burrows (10/16/2007)* -1 should workwhat is the datatype and what makes you think it did not workbtwpreceding a column or variable with - will achieve the same, eg DECLARE @myvariable int SET @myvariable = 1 SELECT @myvariable,-@myvariable I think David means ...DECLARE @myvariable intSET @myvariable = 1SELECT @myvariable,@myvariable * -1But BOTH work. It must be a another issue, but I don't think it's a dat-type issue. EDIT: Sorry Guys, I replied WAY to quick, and mis-read David's post ______________________________________________________________________Personal Motto: Why push the envelope when you can just open it?If you follow the direction given HERE you'll likely increase the number and quality of responses you get to your question.Jason L. Selburg
Post #411272
 Posted Tuesday, October 16, 2007 7:39 AM
 SSCertifiable Group: General Forum Members Last Login: Tuesday, October 25, 2016 8:37 AM Points: 6,822, Visits: 8,830
 and if you have doubts, just put it between brackets.SELECT @myvariable,@myvariable *(-1) JohanDon't drive faster than your guardian angel can fly ...but keeping both feet on the ground won't get you anywhere - How to post Performance Problems- How to post data/code to get the best help- How to prevent a sore throat after hours of presenting ppt ?"press F1 for solution", "press shift+F1 for urgent solution" Need a bit of Powershell? How about thisWho am I ? Sometimes this is me but most of the time this is me
Post #411287
 Posted Tuesday, October 16, 2007 7:54 AM
 SSC Eights! Group: General Forum Members Last Login: Monday, April 14, 2014 6:47 AM Points: 967, Visits: 450
 I don't think braces would really matter. It should work even without braces. But as a safety you can try it with braces. Prasad Bhogadiwww.inforaise.com
Post #411302
 Posted Tuesday, October 16, 2007 8:07 AM
 SSCertifiable Group: General Forum Members Last Login: Tuesday, October 25, 2016 8:37 AM Points: 6,822, Visits: 8,830
 indeed. JohanDon't drive faster than your guardian angel can fly ...but keeping both feet on the ground won't get you anywhere - How to post Performance Problems- How to post data/code to get the best help- How to prevent a sore throat after hours of presenting ppt ?"press F1 for solution", "press shift+F1 for urgent solution" Need a bit of Powershell? How about thisWho am I ? Sometimes this is me but most of the time this is me
Post #411309
 Posted Wednesday, October 17, 2007 9:40 AM
 SSC Eights! Group: General Forum Members Last Login: Friday, January 6, 2012 2:39 PM Points: 954, Visits: 683
 DECLARE @a INTSELECT @a = 1SELECT @a = -@aSELECT @aSELECT @a=-@aSELECT @aNote that @a*-1 doesn't change it unless you set it to itself.. Is that why you thought it didn't work?
Post #411804
 Posted Thursday, October 18, 2007 8:27 AM
 SSC Journeyman Group: General Forum Members Last Login: Friday, July 22, 2016 6:16 AM Points: 86, Visits: 69