You are here: Re: Question on scripting « MsSQL Server « IT news, forums, messages
Re: Question on scripting

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация