Query/Stored Proc Help

  • Thread starter Thread starter Jay
  • Start date Start date
J

Jay

I have a table view with the following fields:

fr_mileage
fr_24
fr_36
fr_48

What I want is a query/stored proc that returns

all fr_24 values where fr_mileage=40
all fr_36 values where fr_mileage=60
all fr_48 values where fr_mileage=80

I appreciate this is probably going to involve subqueries but can't seem to
get it right.

ANY help greatly appreciated......thanks, Jason
 
Use an Union query or a Case statement:

Select fr_24 as FR from T1 where fr_mileage=40
Union All
Select fr_36 as FR from T1 where fr_mileage=60
Union All
Select fr_48 as FR from T1 where fr_mileage=80

or with the Case statement:

Select Case when fr_mileage=40 then fr_24 when fr_mileage=60 then fr_36 else
fr_48 End as FR
From T1 where fr_mileage in (40, 60, 80).

Notice that this kind of example rises the suspicion of a not-normalized
design. Also, it would be best to post this type of question in the
m.p.sqlserver.programming newsgroup.
 
Thanks for the help. I agree the tables aren't normalised, but I'm simply
viewing & querying our company's main sql tables, the design of which is
I.T's responsibility.

Thanks for the help. I've since subscribed to sqlserver.newusers &
sqlserver.programming for similar posts in the future,

Many thanks.....Jason
 
Back
Top