|
Posted by Roy Harvey on 10/25/06 20:07
On 25 Oct 2006 11:30:11 -0700, "mike" <mike.a.rea@gmail.com> wrote:
>I can do this obviously using multiple When Then Else statements.
>Like
>
>Case when method='L'
> then Price * (1+(percentage/100))
> else case when method='D'
> then Price * (1-(percentage/100))
> else Cost * (1+(percentage/100))
> end
>end
>
>However I was thinking there might just be a better way to do this that
>I am not familar with, plus I could easily have 8-10 of these methods
>that I need to code.
You have overly complicated this CASE expression. It does NOT require
nesting, and either format will handle ten (or fourty) alternative
calculations without becoming awkward.
CASE WHEN method='L'
THEN Price * (1+(percentage/100))
WHEN method='D'
THEN Price * (1-(percentage/100))
WHEN method='U'
THEN Cost * (1+(percentage/100))
END
or:
CASE method
WHEN 'L' THEN Price * (1+(percentage/100))
WHEN 'D' THEN Price * (1-(percentage/100))
WHEN 'U' THEN Cost * (1+(percentage/100))
END
Roy Harvey
Beacon Falls, CT
Navigation:
[Reply to this message]
|