Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query - conditional select

Author  Topic 

Mopani
Yak Posting Veteran

55 Posts

Posted - 2009-06-19 : 04:22:15
I use SQL server 2008 and VWDexpress.
I am trying to write a query based on another query.
In the SQL code I have the following...
SELECT     ID, firName, surname, Squad, batHand, bowHand, talOne, talTwo, bat, bow, tech, pow, skTalBoost
FROM dbo.Squad_Full_1

What I want is to manipulate "tech" based on the value of "talOne" and "talTwo" so that it conforms to the following logic.

If talOne = 4 or if talTwo = 4 then tech = tech * skTalBoost + tech

Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-19 : 04:25:50
SELECT ID, firName, surname, Squad, batHand, bowHand, talOne, talTwo, bat, bow,
case when 4 in (talone, taltwo) then tech * sktalboost + tech else tech end as tech,
pow, skTalBoost
FROM dbo.Squad_Full_1



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Mopani
Yak Posting Veteran

55 Posts

Posted - 2009-06-19 : 04:35:21
Super Super Super !!!
Thanks for the fast response. You're awesome.
Go to Top of Page

Mopani
Yak Posting Veteran

55 Posts

Posted - 2009-06-19 : 12:31:54
I want to take this a step further in another query that will be based on this query, to display data that follows the following logic...

I want a value called boPenal
= if tagSkGapPen = 'Off' then boPenal = 0
else if bow - tech <= 1 then boPenal = 0
else ((bow - tech) - 1) * 0.5

SELECT ID, firName, surname, Squad, batHand, bowHand, talOne, talTwo, bat, bow, tech, pow, skTalBoost, tagSkGapPen
FROM dbo.Squad_Full_1
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-19 : 13:15:37
[code]
SELECT ID, firName, surname, Squad, batHand, bowHand, talOne, talTwo, bat, bow,tech,
pow, skTalBoost,boPenal = case when tagSkGapPen = 'Off' then 0
when bow - tech <= 1 then 0
else ((bow - tech) - 1) * 0.5
end
FROM
(
SELECT ID, firName, surname, Squad, batHand, bowHand, talOne, talTwo, bat, bow,
case when 4 in (talone, taltwo) then tech * sktalboost + tech else tech end as tech,
pow, skTalBoost
FROM dbo.Squad_Full_1
)t
[/code]
Go to Top of Page
   

- Advertisement -