+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: Trying to get sum help

  1. #1
    Barn Legend Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    1,522
    Rep Power
    5

    Trying to get sum help

    Hi All,

    I've attached an excel spreadsheet of current query results...and what the data looks like. Currently, I am querying the in first criteria row:
    LocCode = HD and LocNameCtr Like "*repair*" And Not Like "*HD*"
    then in second criteria row:
    LocCode = HD and LocNameCtr Like "*repair*" And Like "*HD*"

    Because I want to get sum Amt and sumCount where the LocCode is in the LocNameCtr because this tells me its an Internal repair sum/count. then where the LocNameCtr contains "*repair*" and not the LocCode "*HD*"..this tells me its in repair but not locally because HD is not in the LocNameCtr.

    Hope that makes sense.
    Attached Files

  2. #2
    Barn Legend Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    1,522
    Rep Power
    5

    Hi All,

    Ok, I've still not gotten a solution for this and feel like I've been banging my head against the wall...but after thinking a bit more...maybe I need something extra to label/tag each with either Internal or External with an "IF" statement then try to sum when grouping Internal/External.

    But how can I create an IF statement in access depending on 2 different fields?

  3. #3
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    You mean:
    Code:
      Select  LocName, sum(sumAmt), sum(sumCount) 
        From  aTable
      Where <your first criteria>
      Group By LocName
      Union
      Select LocName, sum(sumAmt), sum(sumCount)
       From aTable
      Where <your second criteria>
      Group by LocName
    
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  4. #4
    Barn Legend Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    1,522
    Rep Power
    5

    Heya W0lffy,

    I keep getting basically the same results with the union so I must be doing something wrong or my data is not correct.

    Do you mind if I email you my access db?

    Or I need to start over and list my table structure with some data here so you can see what I'm trying to get.

    Thankies!

  5. #5
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    I don't have access, so it wouldn't do me any good. Post your query however. What do you mean by 'same results'? Same as what?
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  6. #6
    Barn Legend Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    1,522
    Rep Power
    5

    okies...

    I had to redo I guess I messed with it again after I was getting same results but now I get an error:

    Code:
    SELECT qryTonyFirstTestRun2.LocName,
    Sum(qryTonyFirstTestRun2.SumOfDEPR_CYR_AMT) AS SumOfSumOfDEPR_CYR_AMT, 
    Sum(qryTonyFirstTestRun2.SumOfMonthCounter) AS SumOfSumOfMonthCounter, 
    qryTonyFirstTestRun2.MonthYR, 
    qryTonyFirstTestRun2.Districtcode
    FROM qryTonyFirstTestRun2
    WHERE (((qryTonyFirstTestRun2.FUNC_LOC_CD) Like "*Repair*"))
    GROUPBY qryTonyFirstTestRun2.LocName
    
    UNION
    
    SELECT qryTonyFirstTestRun2.LocName,
    Sum(qryTonyFirstTestRun2.SumOfDEPR_CYR_AMT) AS SumOfSumOfDEPR_CYR_AMT, 
    Sum(qryTonyFirstTestRun2.SumOfMonthCounter) AS SumOfSumOfMonthCounter, 
    qryTonyFirstTestRun2.MonthYR, 
    qryTonyFirstTestRun2.Districtcode
    FROM qryTonyFirstTestRun2
    WHERE (((qryTonyFirstTestRun2.Districtcode) Like "*OK*"))
    
    GROUPBY qryTonyFirstTestRun2.LocName
    
    This is error:
    Code:
    Syntax error (missing operator) in query expression '(((qryTonyFirstTestRun2.FUNC_LOC_CD) like "*Repair*")) GROUPBY qryTonyFirstTestRun2.LocName'.
    
    This is a new query from the query where I pull all the districtcodes I want to see that are in a repair center. This step I want to get the sum of count and dep amt for each district code that are in an internal repair ctr and then same for external repair ctr. To help determine that is, if the distcode ex: HD is located in the FuncName its internal but if it doesn't contain the district in the FuncName then its external.
    Last edited by Rebelle; January 11th, 2010 at 01:44 PM. Reason: added last paragraph.

  7. #7
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    Group By is two words
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  8. #8
    Barn Legend Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    1,522
    Rep Power
    5

    Ok, I think I'm getting very confused...

    In posting above my where clause is stating in 1st select anything with "repair" but in my 2nd I have a criteria for the district code.

    Are both my where clauses suppose to be querying the same field?

    It looks like I'm getting 1 results for each district when I need 2. using this query:
    Code:
    SELECT qryTonyFirstTestRun2.LocName,
    Sum(qryTonyFirstTestRun2.SumOfDEPR_CYR_AMT) AS SumOfSumOfDEPR_CYR_AMT, 
    Sum(qryTonyFirstTestRun2.SumOfMonthCounter) AS SumOfSumOfMonthCounter, 
    qryTonyFirstTestRun2.Districtcode
    FROM qryTonyFirstTestRun2
    WHERE (((qryTonyFirstTestRun2.FUNC_LOC_CD) Like "*Repair*"))
    GROUP BY qryTonyFirstTestRun2.LocName,qryTonyFirstTestRun2.Districtcode
    
    UNION
    
    SELECT qryTonyFirstTestRun2.LocName,
    Sum(qryTonyFirstTestRun2.SumOfDEPR_CYR_AMT) AS SumOfSumOfDEPR_CYR_AMT, 
    Sum(qryTonyFirstTestRun2.SumOfMonthCounter) AS SumOfSumOfMonthCounter,  
    qryTonyFirstTestRun2.Districtcode
    FROM qryTonyFirstTestRun2
    WHERE (((qryTonyFirstTestRun2.FUNC_LOC_CD) Not Like "*Repair*"))
    
    GROUP BY qryTonyFirstTestRun2.LocName,qryTonyFirstTestRun2.Districtcode
    
    
    LocName	SumOfSumOfDEPR_CYR_AMT	SumOfSumOfMonthCounter	Districtcode
    Houston	-4021881.22	296	HD
    Oklahoma	-3530685.38	240	OK
    
    Since my first query that I'm querying off of now contains every districtcode I'm looking for using (IN "AK", "HD", "OK") with funcName *repair* this gives me all items in a repair ctr in all those districts. but now I want to get 2 results for each district (one that gives me the sum of count and dep amt) for items in a internal rep. ctr. and one for items in an external repair ctr.
    Is this possible?

    Thanks for your patience.
    Last edited by Rebelle; January 11th, 2010 at 02:10 PM.

  9. #9
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    It appears that 1 of the queries is not returning anything. Add the following to the Select statements after DistrictCode:
    'Repair' as Rectype in the first query
    'Not Repair' in the second query

    Also, run each part of the UNION separate to see which is returning what.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  10. #10
    Barn Legend Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    1,522
    Rep Power
    5

    Excellent!!! I was able to see the 2nd wasn't working properly....too many things on the brain wasn't thinking about it correctly. I changed and it now looks like this and returning 2 results for each districtcode and summing according to whether its internal or external.

    Code:
    SELECT qryTonyFirstTestRun2.LocName,
    Sum(qryTonyFirstTestRun2.SumOfDEPR_CYR_AMT) AS SumOfSumOfDEPR_CYR_AMT, 
    Sum(qryTonyFirstTestRun2.SumOfMonthCounter) AS SumOfSumOfMonthCounter, 
    qryTonyFirstTestRun2.Districtcode,'Repair' as Rectype
    FROM qryTonyFirstTestRun2
    WHERE (((qryTonyFirstTestRun2.Districtcode) Like "*OK*")) And (((qryTonyFirstTestRun2.Func_Loc_CD) Like "*OK*")) OR (((qryTonyFirstTestRun2.Districtcode) Like "*HD*")) And (((qryTonyFirstTestRun2.Func_Loc_CD) Like "*HD*"))
    GROUP BY qryTonyFirstTestRun2.LocName,qryTonyFirstTestRun2.Districtcode
    
    
    UNION
    
    SELECT qryTonyFirstTestRun2.LocName,
    Sum(qryTonyFirstTestRun2.SumOfDEPR_CYR_AMT) AS SumOfSumOfDEPR_CYR_AMT, 
    Sum(qryTonyFirstTestRun2.SumOfMonthCounter) AS SumOfSumOfMonthCounter, 
    qryTonyFirstTestRun2.Districtcode,'Repair' as Rectype
    FROM qryTonyFirstTestRun2
    WHERE (((qryTonyFirstTestRun2.Districtcode) Like "*OK*")) And (((qryTonyFirstTestRun2.Func_Loc_CD) Not Like "*OK*")) OR (((qryTonyFirstTestRun2.Districtcode) Like "*HD*")) And (((qryTonyFirstTestRun2.Func_Loc_CD) Not Like "*HD*"))
    GROUP BY qryTonyFirstTestRun2.LocName,qryTonyFirstTestRun2.Districtcode
    
    But my next question is....instead of having to hardcode for each districtcode where, is there a way to look up all the codes I have my my loccode table without this sqlview messing up?

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO