March 22, 2007 at 7:47 am
Hi,
the values created in my view by this select statement carry through negative numbers as "Scrap" bookings on our system are always negative adjustments.
CAST(sum(case when datepart(yyyy,dateadd(mm,-1,getdate())) = TrnYear and datepart(mm,dateadd(mm,-1,getdate())) = TrnMonth then TrnQty else 0 end) as int) as "CurMonth-1",
How can I add something here to take away the "-" from the number, I need to do this because the Crystal report I'm using to produce a graph needs positive numbers else the graph goes the wrong way.
Any help appreciated,
Craig Lloyd
March 22, 2007 at 8:11 am
Hello Craig,
Can you try this logic to test?
declare @num real
set @num = -10
select cast(replace(convert(varchar, @num), '-', '') as int)
you can substitue your column name for @num local variable. if your column is already an int datatype, then you can use
select cast(replace(convert(varchar, <your column>, '-', '') as int)
Thanks
Lucky
March 22, 2007 at 8:18 am
March 22, 2007 at 8:34 am
yey hey,
cheers guys,
Thanks, the *-1 was the easiest to implement in my script, thanks a lot.
March 22, 2007 at 9:01 am
Craig
Yes, since all your values are negative, this will work:
UPDATE MyTable SET MyNum = MyNum * -1
WHERE <whatever>
But if you didn't know whether the values would be be positive or negative, you could use the ABS function, which returns the non-negative value of a number:
UPDATE MyTable SET MyNum = ABS(MyNum)
WHERE <whatever>
John
March 22, 2007 at 9:32 am
Hi,
there is a built in function to do this. look up abs in BOL.
HTH
Paul
March 22, 2007 at 9:35 am
March 22, 2007 at 9:50 am
True, depending on the requirement. Sometimes you are only interested in the size of a number, which, in the case of a scalar, means its distance from zero. For example, if you were measuring the height of stalagmites and stalactites, you might have stalagmites with positive values since their tip is above their base, but stalactites would have negative values because the tip is below the base. However, in one report, you may be interested only in the absolute length of the rock formation, in which case you would use the ABS function.
John
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply