[thelist] MS SS7 - SELECT [computed field] syntax question

Matt Warden mwarden at gmail.com
Fri Jan 25 11:52:53 CST 2008


On 1/25/08, Luther, Ron <Ron.Luther at hp.com> wrote:
> I'm looking for the MS SQL7 syntax for selecting a computed
> field.  (I generally use Oracle where the syntax is, I suspect,
> different.)
>
> This computed field would involve some case or nested if logic:
>
> SELECT
>         Field_1,
>         Field_2,
>         Field_3,
>         (If ((Field_1="XX") AND (Field_2="YY")), "New Value", Field_3) as New_Field_3
> FROM Table
>
> {Where "New Value" is the result where the compound condition was True
> and 'Field_3' would be the default value.}

I don't know about MS SQL's special sauce way of doing it, but this is
how I'd do it:

select
...
(case when Field_1='XX' and Field_2='YY' then 'New Value' else Field_3
end) as New_field_3
from ...
...;

hth,

-- 
Matt Warden
Cincinnati, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the thelist mailing list