Lunyx
Lunyx

Reputation: 3284

How can I use a MAX(ABS(decimal)) in a PIVOT?

I have the following PIVOT currently:

PIVOT
(
    MAX(Value)
    FOR [Month] IN
    ( [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12] )
)

I want to modify the MAX(Value) to MAX(ABS(Value)), but it gives me an error saying Incorrect syntax near 'Value'. Expected '(' OR SELECT). I tried doing a SELECT MAX(ABS(-5.0001)) by itself and it works, so why doesn't it work when I use it within the pivot? How can I fix this?

Upvotes: 0

Views: 204

Answers (1)

Pரதீப்
Pரதீப்

Reputation: 93724

I will suggest you to do the absolute conversion(abs) in pivot source query

select * from 
(
select abs(value) value,... from yourtable
) a
PIVOT
(
    MAX(Value)
    FOR [Month] IN
    ( [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12] )
)

Upvotes: 1

Related Questions