|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
IF statement within a SELECT??? HELP?
I need to do an if statement within a select... I have basically this...
SELECT (If a price >200, enter value 'Expensive' into the column... else enter value 'Value') AS PriceType FROM ... Can someone convert that English to SQL? I've tried a few things, to no avail, and would prefer not to create a view just to do this... Thanks! |
|
#2
|
||||
|
||||
|
Anyone, please??? I'm dyin' here...
![]() |
|
#3
|
||||
|
||||
|
Code:
select case when price > 200
then 'Expensive'
else 'Value' end as PriceType
from ...
|
|
#4
|
||||
|
||||
|
SELECT A.Name, A.Gender, SA.SalePrice AS Price, (SELECT CASE SA.SalePrice > 200 THEN 'Expensive' ELSE 'Value' END) AS PriceType
FROM Animal A, SaleAnimal SA WHERE A.AnimalID = SA.AnimalID AND A.Category = @BCategory AND A.Breed = @breed ORDER BY A.Name ASC Is this right? Still not working properly... |
|
#5
|
||||
|
||||
|
Code:
select A.Name
, A.Gender
, SA.SalePrice as Price
, case when SA.SalePrice > 200
then 'Expensive'
else 'Value' end AS PriceType
from Animal A
inner
join SaleAnimal SA
on A.AnimalID = SA.AnimalID
where A.Category = @BCategory
and A.Breed = @breed
order
by A.Name asc
|
|
#6
|
||||
|
||||
|
Got it, was missing one keyword... appreciate the help.
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > IF statement within a SELECT??? HELP? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|