• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

sum 2 columns

Guest
May 11, 2006 May 11, 2006

Copy link to clipboard

Copied

Hi i am using this statement in my query

SUM(Iif (BatRuns >= 100, 1, 0)) AS Hundred

this works fine but i now need to add another column BatRuns2 to this i have tried

SUM(Iif (BatRuns >= 100, 1, 0)(BatRuns2 >= 100, 1, 0)) AS Hundred

just not sure how to do it
can someone help
thanks
TOPICS
Advanced techniques

Views

591

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 11, 2006 May 11, 2006

Copy link to clipboard

Copied

quote:

Originally posted by: JohnGree
Hi i am using this statement in my query

SUM(Iif (BatRuns >= 100, 1, 0)) AS Hundred

this works fine but i now need to add another column BatRuns2 to this i have tried

SUM(Iif (BatRuns >= 100, 1, 0)(BatRuns2 >= 100, 1, 0)) AS Hundred

just not sure how to do it
can someone help
thanks

I don't know the answer, but, usually when you want to add two numbers together you put a plus sign between them. If that is not what you are attempting, your question is too vague.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 11, 2006 May 11, 2006

Copy link to clipboard

Copied

ok sorry what i need to do is count how many time 100 or more appears in columns

batruns
and
batruns2

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 11, 2006 May 11, 2006

Copy link to clipboard

Copied

Does you db support this syntax?
select case
when this then that
when these and those then the_other_one
else something_else
end as something

If so, it would be a better approach.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 11, 2006 May 11, 2006

Copy link to clipboard

Copied

i am using microsoft access, not sure if this code would work

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 11, 2006 May 11, 2006

Copy link to clipboard

Copied

For EITHER column having >= 100:
SUM (Iif ( (BatRuns >= 100) OR (BatRuns2 >= 100), 1, 0) ) AS Hundred

For BOTH columns having >=100 simultaneously:
SUM (Iif ( (BatRuns >= 100) AND (BatRuns2 >= 100), 1, 0) ) AS Hundred

Edit: fixed parenthesis

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 11, 2006 May 11, 2006

Copy link to clipboard

Copied

For SUM of columns >= 100:
SUM (Iif ( (BatRuns + BatRuns2 ) >= 100, 1, 0) ) AS Hundred



Edit: fixed parenthesis

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 21, 2006 May 21, 2006

Copy link to clipboard

Copied

LATEST
Thanks for that i have used
SUM (Iif ( (BatRuns >= 100) OR (BatRuns2 >= 100), 1, 0) ) AS Hundred

but it only ads the BatRuns2 column, not sure why this is

i just need to count the number of times 100 or more appears in these columns, the code seams logical to me but doesnt work

any ideas

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation