Thread: Weigh resultset
View Single Post

   
  #3 (permalink)  
Old 02-28-2008, 06:25 PM
Steve Kass
 
Posts: n/a
Default Re: Weigh resultset

Doug,

You've got some simple syntax errors. Does this help?

select
firstname,
lastname,
case
when notes like '%BA%' then 1
when notes like '%BTS%' then 2
else 0 end as aiCOL
from Northwind..Employees
where notes LIKE '%BA%' or notes LIKE '%BTS%'

-- Steve Kass
-- Drew University
-- Ref: 5CAD7D03-5761-4ECC-8E43-82E2A0F67529

Doug Baroter wrote:

>Hi,
>
>This is what I want to do. For a data acquisition query, if condition
>A is met, set weight to 1, else if condition B is met, set weight to 2
>etc.
>Is this possible? I thought about using CASE function but to no
>avail.
>
>Using the classical Northwind db as target db, and its employees table
>as target table, if [note] column contains 'BA', then I want to set
>weight to 1, else if it contains 'BTS', then I want to set weight to 2
>etc. Weight or the like is an auxillary artificially created column.
>
>Something like
>
>DECLARE @col int
>
>select firstname, lastname, @col =
> (
> CASE notes
> when '%BA%' then 1
> when '%BTS%' then 2
> else 0
> END as aiCOL
> )
> -- and I'd like to alias @col as aiCOL or whatever
>from employees
>where notes LIKE
> '%BA%'
> OR
> notes LIKE '%BTS%'
>
>failed.
>
>Thanks.
>
>


Reply With Quote