If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > SQL Help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-29-03, 21:32
bambamn007 bambamn007 is offline
Registered User
 
Join Date: Jan 2003
Posts: 32
SQL Help

I have this string:

SELECT *,
IIF(outcome='win',2,1) AS points FROM Results
WHERE name='Bam'

What I need to do now, in this string, is have it total the rows in the points column that I have created in the statement. I tried this:

SELECT *,
IIF(outcome='win',2,1) AS points FROM Results
WHERE name='Bam'
SUM points AS points2

But it didn't work. Everyting I tried didn't work. Can someone help me with this please?
Bam
Reply With Quote
  #2 (permalink)  
Old 03-31-03, 14:18
MrWizard MrWizard is offline
Registered User
 
Join Date: Mar 2003
Location: Atlanta, GA
Posts: 191
Maybe I'm missing something, but it seems to me that

SELECT SUM(IIF(outcome='win',2,1)) AS points FROM Results WHERE name='Bam"

should work... Try it.

Tim
__________________
Tim
Reply With Quote
  #3 (permalink)  
Old 03-31-03, 14:28
bambamn007 bambamn007 is offline
Registered User
 
Join Date: Jan 2003
Posts: 32
yep, worked great! Thanks a bunch!
Bam
Reply With Quote
  #4 (permalink)  
Old 03-31-03, 15:04
bambamn007 bambamn007 is offline
Registered User
 
Join Date: Jan 2003
Posts: 32
Thanks to all who have helped me with Sql. I am getting to understand SQL much better. I do have another question though.
In the string that you gave me, would there be anyway of putting some kind of if statement in there? This is what I want.
I have this:

select sum(IIF(outcome='win',2,1)) as points
FROM Results
WHERE name='Bam'

now what I need, is to tell it, if the name Bam appears more than 10 times, not to include it in the total. In other words, a player can only play 10 matches that count, so I want to NOT include anything over 10, or throw it out so to speak. Can this be done?
Bam
Reply With Quote
  #5 (permalink)  
Old 04-06-03, 03:51
kaeldowdy kaeldowdy is offline
Member
 
Join Date: Apr 2003
Location: Evansville, Indiana
Posts: 75
Lightbulb

Not sure if this will work for you...but try something like this.

select Sum(IIf(sum(IIF(outcome='win',2,1)) > 10, 0, sum(IIF(outcome='win',2,1)))) as points
FROM Results
WHERE name='Bam'

You may not need that final outer Sum()...but this may help.

Kael
Reply With Quote
  #6 (permalink)  
Old 10-08-03, 13:37
christodd christodd is offline
Registered User
 
Join Date: Oct 2003
Posts: 16
Quote:

now what I need, is to tell it, if the name Bam appears more than 10 times, not to include it in the total. In other words, a player can only play 10 matches that count, so I want to NOT include anything over 10, or throw it out so to speak. Can this be done?
Bam
I don't know about the SQL server you are using, but I'm using mySQL and I can use the LEAST function

select LEAST(10,IIF(......))

-Chris
Check out my SQL tutorial at http://www.bitesizeinc.net/index.php/sql.html
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On