Help with group by

Can anyone tell why this query isn't working? It returns NOT a group by expression error. It has something to do with the subquery but I know I can't group by the alias of that statement. Any help would be appreciated.
SELECT acc.uprn,
NVL (SUM (lth.balance), 0) balance,
(SELECT SUM (balance)
FROM lsc_transaction_history lth
WHERE acc.account_no = lth.account_no
AND SUBSTR (lth.account_no,10,3) = 450) repair_balance
FROM lsc_occupants occ,
lsc_account acc,
lsc_area lmc,
hpm_view_property p,
lsc_account_parties_view accn,
lsc_transaction_history lth
WHERE occ.seq_no = acc.seq_no
AND acc.uprn = occ.uprn
AND occ.account_type = acc.account_type
AND lmc.code = acc.area_code
AND p.uprn = occ.uprn
AND accn.account_no = acc.account_no
AND lth.account_no = acc.account_no
GROUP BY acc.uprn

Well, the hints were already given, but maybe an example make it clearer.
SQL> create table lsc_account
  2  as
  3  select 1 uprn, '100000000000' account_no from dual union all
  4  select 1, '100000000450' from dual union all
  5  select 2, '100000000450' from dual
  6  /
Tabel is aangemaakt.
SQL> create table lsc_transaction_history
  2  as
  3  select '100000000000' account_no, 100 balance from dual union all
  4  select '100000000000', 200 from dual union all
  5  select '100000000000', 300 from dual union all
  6  select '100000000450', 400 from dual union all
  7  select '100000000450', 500 from dual
  8  /
Tabel is aangemaakt.
SQL> SELECT acc.uprn
  2       , NVL (SUM (lth.balance), 0) balance
  3       , ( SELECT SUM (balance)
  4             FROM lsc_transaction_history lth
  5            WHERE acc.account_no = lth.account_no
  6              AND SUBSTR (lth.account_no,10,3) = 450
  7         ) repair_balance
  8    FROM lsc_account acc
  9       , lsc_transaction_history lth
10   WHERE lth.account_no = acc.account_no
11   GROUP BY acc.uprn
12  /
          WHERE acc.account_no = lth.account_no
FOUT in regel 5:
.ORA-00979: Geen GROUP BY-uitdrukking.
SQL> select acc.uprn
  2       , nvl(sum(lth.balance),0) balance
  3       , nvl(sum(case substr(lth.account_no,10,3) when '450' then balance end),0) repair_balance
  4    from lsc_account acc
  5       , lsc_transaction_history lth
  6   where lth.account_no = acc.account_no
  7   group by acc.uprn
  8  /
UPRN      BALANCE REPAIR_BALANCE
   1         1500            900
   2          900            900You only need to access the lsc_transaction_history table once this way.
Regards,
Rob.

Similar Messages

  • Please Help with group chat probs

    I don't get any sound or vibe notification for my group chats also In my group chats if a pic is posted and then comments made on that pic I can't scroll up or down to see all comments. This is something I need to fix as we use pic with chats at work.  I can't get the info I need.  If any one could help with this problem please do. This problem has only been since I upgraded to the newest bbm messenger last week. I have the Q10. I pulled the battery and sims card but this did nothing to fix the problem. Please if anyone can help!
    Thank you all  

    Please make sure you are using TRUCN() in your GROUP BY expression. This function will truncate the date by removing time content.
    Best of luck!

  • Alright I give! I need some help with groups/busses and more please..

    Hi all,
    Well, its now been a few weeks of my off and on testing with my new Logic Rig, I have every plug I can transfer over to UB that I can and now am trying to get deeper into things.
    First I struggled with learning the environment (I still dont get it fully) but now I am really confused about group and fx tracks.
    - Am I missing something or is everything just a buss turned into a group? This also included creating an FX track?
    If this is the case then its not nearly as complex as I think it is but I cant figure certain things out with the way logic handles naming in regards to its busses.
    Lets say I want to create a sidechain group. I take an audio track change it to represent buss (1), I then rename buss 1 to SC-GROUP, now any window that I drop down to find the newly names SC-GROUP always remains named as buss (1). This even happens when I rename the buss direct from the audio environment.
    I must be missing something, whats been confusing the heck out of me is that no matter how I try and name things they always remain their original names in any menues as the example of the buss (1), so how do I rename these channels so I can clearly know exactly where I am routing audio?
    So lets summarise where I am lost so far hehe.
    1. Are groups really just empty busses renamed to act as a group?
    2. How can I rename a buss/group and be able to see the renamed channel in the menues.
    and for the 3rd new question of sorts...
    3. FX Sends, again is this just a buss that has an AU inserted into its channel and then rout the insert of an additional audio channel to the buss with the FX inserted?
    and now my last uestion of the day if I have not confused you to death so far
    Why is it that when I add a AU lets say battery as instrument 1, when I add another in the window and I rerout an instrum,ent track the next AU shows up at the bottom of the list instead of inst. 2?
    If I am not explaining myself clearly enough for any of my examples let me know so I can try to better represent my questions. I am still so new to Logic and still have yet to get the bulk of the simple operations down just yet..
    Thanks again for all your asistance!

    Thank you guys,
    So if I understand right, a sub buss is nothing more than a routing the output of a few channels to a buss to control a few aspects like I had mentioned compressing an entire group of tracks EG: a drum buss (in this situation a drum sub buss?).
    So I will have to reffer to the manual again to read the details on an actual group since it does seem there is a difference EG: the group can actually manipulate the faders of channels routed to the group?
    FX busses seem to be just that, slap an FX info either and AUX channel or a buss and then set the insert of that AUX or buss desired.
    The reason I asked about naming is that lets say I have 6 effects tracks I wish to use lets say as an example AUX1=Short Delay, AUX2=Long Filter Delay, AUX3=Slap Verb, AUX4=Long Verb and so forth.
    When I go to actually use these inserts I need to assume I know exactly what AUX I assigned each effect to, if I could simply rename this AUX track to refference the effect it would make so much more sense then trying to remember what AUX5 was.
    In regards to my last question here is a bit more of a detailed explanation, please bare with me as I am not in front of my computer.
    1. I add battery into Audio Instrument-1
    2. I then configure my environemt to use my AUXs I already have inplace for audio routing.
    3. I then edit the Audio window create the midi for a new multi-instrument.
    4. I come back to the main arrange window and hold-click on the next available audio-instrument and in the instrument window battery will be instrument 1 out of how ever many blanks apear EG:25+
    5. Now I go to add lets say Stylus RMX into the next available mutli audio instrument. I then repeat steps 2,3,4.
    Now when I get to step 4 this time instead of audio instrument 2 from the lint being Stylus it shows up as the last possible instrument in the drop list that appears under audio instrument from hold-click on the audio-instrument track.
    Its just odd, it should be instrument 2, but instead it shows up as the last possible choice.
    Maybe I am doing something wrong, even sometimes when I grab on of batteries midi tracks and create next object I will get a random audio track in there out of no where, or maybe its just a bug with battery.
    Any ideas? If I still am not describing this right, I will post a step by step this eve of exactly the steps I am taking.
    Thanks again, this forum has been very helpful in getting me going with the questions I just cant seem to get around from my Nuendo work flow.
    Cheers!

  • Help with Groups and Effects

    I'm still fairly new to Illustrator so even when I tried to Google for my solution I didn't know how to word it properly so I though you guys would be able to help me.
    So, basicaly I'n trying to keep my "Flag" effect applied to the ribbon/banner but i want only the top of it to be above the circle. However, if try to take the top selected layers out of the group to place on top of the circle, the "Flag" effect
    resets or if I try putting the cicle in the group it gets the effect applied on to it, which I don't want. Only way I can think of doing it is with a clipping mask but it doesnt look so great :/

    Both Groups and Layers are nothing but sets of objects which are contiguous (next to each other) in the object stacking order. Just think of them as "brackets" around a portion of a list for organizational and selection convenience.
    All objects reside on a Layer. Layers contain Groups and objects, because a Group is a kind of object in the same sense that a set of objects in set theory is itself treated as an object. Layers are not contained in Groups. In Illustrator, all objects are listed in the Layers palette; that does not make them Layers. Layers can exist and be completely empty. Groups can't.
    Objects all exist in a stack. A path is an object. You cannot have one portion of object A in front of object B and another portion of object A behind object B. All such appearances of objects intertwining that way are "faked" by using multiple objects which merely appear to be one object.
    It's not clear from your description what exactly you are trying to accomplish. But basically, you will most easily accomplish it by cutting either the ribbon or the ellipse at places where they don't overlap. Others often trot out recommendations involving clipping masks. In the vast majority of cases, tedious masking is not necessary, and simply cutting a path into two or more objects and restacking them is both easier and simpler in terms of the resulting constructs.
    JET

  • Help with Group Policy

    Hello all,
    I am new to Group Policy. Server is running Windows 2008 R2. All client on Win 7. I have made a folder redirect by creating it on Default Domain Policy instead of creating gpo. Is there a downfall and if so, how do i redo and have it fix ? 

    What if i just let stay without doing or creating the new gpo? let it be on the DDP. any issue will arise or possibilities that might will mess with the system or client pc connected to domain ? 
    You can let it be, it will not cause harm with anything at all.
    It is fine, in a small and simple network, which does not change often, for these things to remain.
    If you have a complex network, with many different GP configurations required, having such settings in your DDP can then be a problem, to achieve your desired different/granular settings, e.g. different settings for different departments.
    If the DDP (which applies to all departments) contains this setting, then, how do you set it differently for two departments?
    But if your network is small and simple, it's fine to do this.
    If you have no expectation that in the future it will cause constraint for you, it's fine like this.
    You can always change it later, but, it might be more effort then, compared to now?
    Don
    (Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable.
    This helps the community, keeps the forums tidy, and recognises useful contributions. Thanks!)

  • Help with grouping similar lines

    Hi,
    could you help me with one sql query in Oracle 11g.
    I have data with two columns - timestamp, counter
    4.7.2012 10:01, 13
    4.7.2012 10:03, 0
    4.7.2012 10:04, 0
    4.7.2012 10:05, 0
    4.7.2012 10:21, 3
    4.7.2012 10:33, 0
    4.7.2012 10:51, 6
    What I need to get is to group lines with counter = 0 which are next to each other and keep the info about start and end of the timestamp.
    so first I need to use rank
    line_number, timestamp, counter, rank
    1, 4.7.2012 10:01, 13, 0
    2, 4.7.2012 10:03, 0, 1
    3, 4.7.2012 10:04, 0, 2
    4, 4.7.2012 10:05, 0, 3
    5, 4.7.2012 10:21, 3, 0
    6, 4.7.2012 10:33, 0, 0
    7, 4.7.2012 10:51, 6, 0
    and then group lines 2, 3, 4 into one line, because line's counter=0 and there is more then one line in the group.
    so the result would be
    4.7.2012 10:01, 13
    4.7.2012 10:03 - 4.7.2012 10:05, 0
    4.7.2012 10:21, 3
    4.7.2012 10:33, 0
    4.7.2012 10:51, 6
    Thanks a lot for any ideas,
    D.
    Edited by: dusoo on Jul 11, 2012 6:37 AM

    Hi,
    You can do something like this:
    WITH     got_grp     AS
         SELECT     tmstmp, counter
         ,     ROW_NUMBER () OVER ( ORDER BY      tmstmp)
              -  ROW_NUMBER () OVER ( PARTITION BY  counter
                                        ORDER BY          tmstmp
                           )     AS grp
         FROM    table_x
    --     WHERE     ...     -- If you need any filtering, do it here
    SELECT       MIN (tmstmp) || CASE        -- You'll probably want to use TO_CHAR here, and 2 lines below
                                  WHEN  COUNT (*) > 1
                         THEN '-' || MAX (tmstmp)
                              END
    ,         counter
    FROM       got_grp
    GROUP BY  counter, grp
    ORDER BY  MIN (tmstmp)
    ;TIMESTAMP is a keyword in Oracle 9 (and up), so it's not a good column name. I used TMSTMP instead.
    This assumes that tmstmp is unique. If not, you'll have to add something to the analytic ORDER BY clauses.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data. For example, what defines a "group" in this problem? It seems to be consectuive rows (in order by tmstmp), but what else? Will all members of a gropup have the same value for counter, regardless of the difference in tmstmp? (That's what I assumed above.) Will all members of a group have tmstmp within 1 minute of another, regardless of counter?
    Always say which version of Oracle you're using.
    See the forum FAQ {message:id=9360002}

  • Need Help with Group Message Glitch

    I am in a group message with about 15 people. Every text comes in as if only one person was sending me a text. Although I can see every person's text, I can not respond. Also, when I press "details" only one person's information and name shows up. Please Help.

    I am in a group message with about 15 people. Every text comes in as if only one person was sending me a text. Although I can see every person's text, I can not respond. Also, when I press "details" only one person's information and name shows up. Please Help.

  • [JS] CS3 Help with groups needed

    Hi.
    I am formatting a page of text frames, and images, and trying to group the selected objects together.
    While formatting the pageI am gathering an array of variables:
    myGroupArray = new Array();
    myGroupCounter = 0;
    myGroupArray[myGroupCounter]="myTextFrame";
    myGroupCounter++;
    etc...
    when I am finished a section, I want to group the contents of the vaiable 'myGroupArray'
    I am using this line:
    myGroup = myDoc.groups.add(myGroupArray);
    but getting an error 'Invalid value for parameter 'groupitems' of event 'add'. Expected Array o...t received("myTextFrame","myCorrectPic","myPriceFrame","mtQtyFrame").
    Can someone help me on this?
    Cheers
    Roy

    (Without actually trying it in ID)
    myGroupArray[myGroupCounter]="myTextFrame";
    That adds a string to the array, not the frame. If "myTextFrame" is a variable pointing to a text frame, simply use
    myGroupArray[myGroupCounter]=myTextFrame;
    By the way, have you been programming in other languages in the past? I have, and used
    myGroupCounter++;
    as well until finding out that for arrays, this built-in array function works equally well:
    myGroupArray.push(myTextFrame);
    Types much faster, and if you need the number of elements, you can always use myGroupArray.length.

  • Need help with Group Headings and showing them on drill down.

    Hi all:
    I think this is a simple question and feel that I should already know the answer but for some reason it eludes me.  What I would like to know is the proper way to hide/display group headings and have them show up on drill down BUT not repeat on each group header.
    What I have for grouping is as follows:
    Group Header #1 u2013 Sales Rep
      Group Header #2 u2013 Customer
        Group Header #3 u2013 Product Class
          Group Header #4 u2013 Stock Code
            Details
          Group Footer #4 u2013 summary calculated on this line
        Group Footer #3  u2013 summary calculated on this line
      Group Footer #2 u2013 summary calculated on this line
    Group Footer #1 u2013 summary calculated on this line
    My goal is to have my report show only the lines listed below by default and allow the user to drill down group by group to the details section:
    Group Header #1 u2013 Sales Rep
      Group Footer #2 u2013 summary calculated on this line
    Group Footer #1 u2013 summary calculated on this line
    If anyone could offer any help it would be greatly appreciated!
    Thanks,
    FatMan

    click section expert, then for example of GH3, highlight it, then click on the formula box for suppression, and put in the code....
    Drilldowngrouplevel < 3
    The result will be that this GH3 is suppressed whenever the report is showing GH1 and 2 but not 3.
    In addition to this, you must Hide(Drill-down ok) GH3. This is also done in the section expert.
    Then just do the same for GF3, and for GH4/GF4 make sure you use...
    Drilldowngrouplevel < 4

  • Need help with group by query with condition

    Name
    ID
    A1
    1
    A2
    1
    A3
    1
    A1
    1
    A2
    2
    A2
    3
    A3
    3
    A1
    4
    A2
    4
    A3
    5
    I want to get result of total count  where ID is less than 4
    A1 - 2
    A2 - 3
    A3 -  2

    Hi,
    If you want to get 0 counts for names that don't have any low ids, then use a CASE expression instead of a WHERE clause.
    You didn't post CREATE TABLE and INSERT statements for your sample data, so I'll use scott.emp to illustrate.
    Say you want to see how many sals in each job are under 3000, like this:
    JOB       UNDER_3_CNT
    CLERK               4
    SALESMAN            4
    PRESIDENT           0
    MANAGER             3
    ANALYST             0
    Here's one way to do that:
    SELECT    job
    ,         COUNT (CASE WHEN sal < 3000 THEN 1 END)  AS under_3_cnt
    FROM      scott.emp
    GROUP BY  job
    This shows that there are ANALYSTs and PRESIDENTs in the scott.emp table; there just don't happen to be any with sals under 3000.

  • Help with Group By on SQL statement

    Iu2019m trying to group by Item Code in the following query, however, I keep receiving the following error message.  Do you know why?
    Msg 306, Level 16, State 2, Line 1
    The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.
    SELECT            dbo.OQUT.DocNum,
                      dbo.OQUT.U_UDF_3 AS QuoteNumber,
                      dbo.OQUT.U_QuoteDesc,
                      dbo.OQUT.U_RevQuote,
                      dbo.OQUT.U_RevDate,
                      dbo.OQUT.DocDate,
                      dbo.OQUT.DocDueDate,
                      dbo.OQUT.U_ReqDate,
                      dbo.OQUT.U_DueDate,
                      dbo.OQUT.CardCode,
                      dbo.OQUT.CardName,
                      dbo.OQUT.CntctCode,
                      dbo.QUT1.LineNum,
                      dbo.QUT1.BaseLine,
                      dbo.QUT1.ItemCode,
                      dbo.QUT1.Dscription,
                      SUM(dbo.QUT1.Quantity),
                      SUM(dbo.QUT1.OpenQty),
                      SUM(dbo.QUT1.U_Original_Qty),
                      dbo.QUT1.U_LeadTime,
                      dbo.QUT1.Price,
                      SUM(dbo.QUT1.LineTotal),
                      dbo.QUT1.unitMsr AS SalUnitMsr,
                      dbo.QUT1.U_UDF_12 AS PNQuoted,
                      dbo.QUT1.U_UDF_13 AS MFRQuoted,
                      dbo.QUT1.U_UDF_16 AS MinQty,
                      dbo.QUT1.U_UDF_17 AS MultiQty,
                      dbo.TBC_AMLPriority1.U_Mfg_Name,
                      dbo.TBC_AMLPriority1.U_Mfg_PN,
                      dbo.QUT1.U_Parent,
                      dbo.ITT1.Quantity AS BOMQty,
                      dbo.OCPR.Name
    FROM         dbo.OQUT INNER JOIN
                      dbo.QUT1 ON dbo.OQUT.DocEntry = dbo.QUT1.DocEntry LEFT OUTER JOIN
                        dbo.OCPR ON dbo.OQUT.CntctCode = dbo.OCPR.CntctCode LEFT OUTER JOIN
    dbo.ITT1 ON dbo.QUT1.ItemCode = dbo.ITT1.Code AND dbo.QUT1.U_Parent =
    dbo.ITT1.Father LEFT OUTER JOIN
                      dbo.TBC_AMLPriority1 ON dbo.QUT1.ItemCode = dbo.TBC_AMLPriority1.U_ItemCode
    WHERE     (dbo.QUT1.Quantity > 0)and dbo.OQUT.DocNum='1'
    GROUP BY    dbo.QUT1.ItemCode,
                dbo.OQUT.DocNum,
                dbo.OQUT.U_UDF_3

    Dear,
    As per your message you mentioned that u r getting following error "
    The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator."
    The error is due to group by of a field whose type is text,ntext.....
    if it is text or ntext just replace that field
    Convert(varchar(100),fieldName)...
    Hope it will help you....
    Regards
    Sanjay

  • Help with Group Left Report

    Hi everyone,
    I created a Group left report with 4 grouping columns.Everthing is working fine but i am getting some problem with the order of the 3rd column(varchar).It is doing ascending order(As the Break order Propoerty of that column is ascending).
    But i am trying to do is the 3 rd column needs to be displayed by a specific (order by clause)
    But in group left report it is not considering the (order by clause of the query).It is doing sort by the grouping columns.Is there any way that i can sort a grouping column(other than asc and dsc).It needs to be displayed in the order of another column.
    Thanks
    phani

    Create another column (either in the query, or in the data model as formula) that would indicated the rank according to the desired sort order. You don't need to place the column into the layout, but use it to set the break order in the data model.

  • Help with GROUP BY with SUM

    Hello all:
    I have always struggled with getting this right, so hopefully someone can assist with this. 
    Basically I have two tables:
    CREATE TABLE [dbo].[Placement](
    [PlacementID] [int] IDENTITY(1,1) NOT NULL,
    [TravelerID] [int] NOT NULL,
    [ActivityTypeID] [int] NULL,
    [ActivityStatusID] [int] NULL,
    [StartDate] [datetime] NULL,
    [EndDate] [datetime] NULL,
    [NumberOfWeeks] [int] NULL,
    [BookingCompanyID] [int] NOT NULL
    CREATE TABLE [dbo].[TravelerCompanyData](
    [TravelerID] [int] NOT NULL,
    [CompanyID] [int] NOT NULL,
    [StatusID] [int] NOT NULL
    I am trying to join the placement table to the TravelerCompanyData table so that I only get one row per TravelerID. The point of this query is to sum up the number of weeks. So I want to sum the number of weeks of Placements that have been completed (if
    any), and add them to however many week the person has been currently on assignment. I cannot use the NumberOfWeeks column if a placement is currently "On Assignment" because it counts the number of weeks from the start date to the end date, and
    the Traveler will not be all the way to the end date yet.
    However, I think with my SUMs in there and all the columns I am referencing in the CASE statement, I am not getting the grouping right. 
    The query below will yield four columns, one for each sum because there are four separate rows in the placement table that fit the criteria of the JOIN/WHERE
    Some notes:
    ActivityStatusID = 23 means the placement status is "on assignment"
    = 24 means the placement in "complete"
    CompanyID 10 and 12 are the only companies that I want to fit this summing criteria. 
    I am using only one travelerID to simplify the result set. 
    SELECT
    trav.TravelerID
    ,CASE
    WHEN p2.EndDate IS NULL -- Not on assignment, can sum number of weeks
    THEN SUM(p.NumberOfWeeks)
    ELSE -- multiple assignments, count weeks
    CASE
    WHEN (DATEDIFF(day, p2.StartDate, GETDATE()) + 1) % 7 < 3
    THEN (DATEDIFF(day, p2.StartDate, GETDATE()) + 1) / 7
    +
    ISNULL(p.NumberOfWeeks,0)
    WHEN (DATEDIFF(day, p2.StartDate, GETDATE()) + 1) % 7 >= 3
    THEN (DATEDIFF(day, p2.StartDate, GETDATE()) + 1) / 7 + 1
    +
    ISNULL(p.NumberOfWeeks,0)
    END
    END AS WksOnAssignment
    FROM TravelerCompanyData trav
    -- Completed placements ------------------
    LEFT JOIN dbo.Placement p ON p.TravelerID = trav.TravelerID
    AND p.ActivityStatusID IN (24)
    AND trav.CompanyID = p.BookingCompanyID
    -- Placement if on assignment ------------
    LEFT JOIN dbo.Placement p2 ON p2.TravelerID = trav.TravelerID
    AND p2.ActivityStatusID IN (23)
    AND trav.CompanyID = p2.BookingCompanyID
    WHERE ( trav.CompanyID IN (10,12))
    AND
    ( p.PlacementID IS NOT NULL
    OR
    p2.PlacementID IS NOT NULL )
    AND trav.TravelerID = 31788
    GROUP BY trav.TravelerID
    ,p.NumberOfWeeks
    ,p2.StartDate
    ,p2.EndDate
    If I add the NumberOfWeeks column in, it is adding that number to the number of weeks the current On Assignment placement currently has for each row (56 weeks), but I need to add that 56 weeks to the sum of the NumberOfWeeks column. Here is the result set:
    TravelerID NumberOfWeeks WksOnAssignment
    31788 8 64
    31788 12 68
    31788 25 81
    31788 33 89
    So am I joining wrong, grouping wrong, or summing wrong? 
    Thanks so much for any pointers!!!

    Thanks for the reply. I did some more experimenting and I discovered I don't need the SUM in this case at all. I get the same results when remove the SUM completely, but still GROUP BY the same columns. 
    Alternatively, if I SUM and the only GROUP BY tcd.TravelerID, I will get one row, but it is summing each NumberOfWeeks value by the result of the expression. 
    Query where I have included the NumberOfWeeks from the p Placement join, and the StartDate and EndDate of p2 Placement table (on assignment match) - NOTE: I have noticed that with this query, the SUM makes no difference:
    SELECT
    trav.TravelerID
    ,p.NumberOfWeeks
    ,p2.StartDate
    ,p2.EndDate
    ,CASE
    WHEN p2.EndDate IS NULL -- Not on assignment, can sum number of weeks
    THEN p.NumberOfWeeks
    ELSE -- multiple assignments, count weeks
    CASE
    WHEN (DATEDIFF(day, p2.StartDate, GETDATE()) + 1) % 7 < 3
    THEN (DATEDIFF(day, p2.StartDate, GETDATE()) + 1) / 7
    +
    ISNULL(p.NumberOfWeeks,0)
    WHEN (DATEDIFF(day, p2.StartDate, GETDATE()) + 1) % 7 >= 3
    THEN (DATEDIFF(day, p2.StartDate, GETDATE()) + 1) / 7 + 1
    +
    ISNULL(p.NumberOfWeeks,0)
    END
    END AS WksOnAssignment
    FROM TravelerCompanyData trav
    -- Completed placements ------------------
    LEFT JOIN dbo.Placement p ON p.TravelerID = trav.TravelerID
    AND p.ActivityStatusID IN (24)
    AND trav.CompanyID = p.BookingCompanyID
    -- Placement if on assignment ------------
    LEFT JOIN dbo.Placement p2 ON p2.TravelerID = trav.TravelerID
    AND p2.ActivityStatusID IN (23)
    AND trav.CompanyID = p2.BookingCompanyID
    WHERE ( trav.CompanyID IN (10,12))
    AND
    ( p.PlacementID IS NOT NULL
    OR
    p2.PlacementID IS NOT NULL )
    AND trav.TravelerID = 31788
    GROUP BY trav.TravelerID
    ,p.NumberOfWeeks
    ,p2.StartDate
    ,p2.EndDate
    Gives:
    TravelerID NumberOfWeeks StartDate EndDate WksOnAssignment
    31788 8 2013-04-01 2014-10-04 64
    31788 12 2013-04-01 2014-10-04 68
    31788 25 2013-04-01 2014-10-04 81
    31788 33 2013-04-01 2014-10-04 89
    See it is summing correctly on the row, but how can I get it to sum the NumberOfWeeks column and add it to 56, which is what the calculation yields from the StartDate of the "On Assignment" placement from p2 until today's date?
    Hope that makes sense! 

  • Help With Grouping Objects

    I have four Pages 2 components (line of a certain color & width which will be used as a border, two text blocks, one masked image) which will hopefully be turned into a business card. Template is laid out and I'd like to move it all to there, but seemingly am unable to.
    I've tried selecting and grouping them ( Arrange >Group) but that doesn't work. I can't get the line object to be selected along with the other three, no matter which selection trick or technique I happen to try. I can select either the bordering line or whatever number of the three other objects, but never all four at the same time.
    Is this a limitation in Pages or am I simply missing something? If it can't be done, can you recommend some other way of getting to the same goal?

    Peggy,
    They may have been, but they're now gone. I gave up on the idea of using lines for borders for another reason, e.g., the measurements get messed up due to how the line is drawn or measured to/from.
    I did move to the AW way of doing it, basically nested 'boxes' of different shapes, all of it to be stacked and then the text boxes/images to be moved onto it.
    Same problem; could not get all of them go Group. In fact, after several tries and undos, I couldn't get any of them to. Pages tends to get lost, I think.
    Ran into other problems also; when the image you are using is a cropped (masked) one, you seem to be stuck with the adjustment bars for the whole thing. The result of this, for example, is seen when you subsequently do Group say that masked image with several other items like text frames or whatever else is working — you wind up with something which can be quite a bit larger than the visual end product.
    The drawback here is seen when you then drop all of it into a template like the one for the business cards; the whole thing gets correspondingly shrunk and the aligment you set up on the master can't be retained.
    Pages seems to have no capability to simply crop/mask off part of an entire construct, identify that as what you really want to play with, and to simply throw away the rest. Some objects I still can't get to group in with the rest, no matter what I do or how I do it.
    Short term workaround was to just put it all together and then take a screenshot of it. That works, and that image can then be dropped into each of the ten slots in the Avery template imported in Pages. It all works, but you do lose some sharpness in the end product.
    Of course, my printer just won't quite feed the Avery sheets correctly and I wind up with those irritating white lines along some of the borders. That's some other issue, however. Oh, well ..........

  • Section Expert Help with Groups

    Hello,
    Seeking assistance with forcing my report groups to print on odd pages.  Essentially, I have letters I need to fold and place in an envelope with a window.  That requires that my print job to print the beginning of every new group on odd pages 1, 3, 5, etc.  Thanks in advance for your attention on this!
    Eddie

    Eddie Gonzalez wrote:>
    > Great!  Thanks for the follow up!  Any idea on how I can suppress all items (Header, footer, etc.) when using your solution?
    You can suppress all the headers and footers except the 2 group footers like normal - for the footers, just size them to almost nothing - you can't size to 0 or they are ignored - even the page breaks (had a LONG conversation about that with customer support but they just didn't "get it")

Maybe you are looking for

  • IMovie audio issues. Fine in timeline, but when rendering to iTunes or Media Browser, audio from certain portions of movie files are heard in places where it shouldn't be !

    iMovie 11  audio issues. Fine in timeline, but when rendering to iTunes or Media Browser, audio from certain portions of movie files are heard in places where it shouldn't be ! I have created a project where I have a montage of photos and video clips

  • Internet on only one computer

    My replacement router [wrt54g ver.1 just replaced by Linksys with wrt54g, ver. 6] is able to connect to the internet from the wired computer and will connect to the remote computer [via a wusb54gp], but the internet is not accesable from the remote c

  • Mbew and other related tables

    Hi all, I need the mbew-peinh field's meaning and other tables related to mbew. I see 1 as the value of mbew-peinh and want to find what does it mean in other tables? Thanks.

  • Checking for a field in tables

    Hi All,     This Quiery is regarding searching for a field   via where used list.Now we can search for a single field ..in which table that field is being used.... 1) Can we make search still specific ..like in which tables that field used as primary

  • Update Problem in Inbound ADRMAS IDOC

    Hi Friends, Presently ADRMAS inbound IDOC creates a log for customer as follows: customer (vd03 or XD03) => Environment >> Account Changes >> All Fields  => All Changes . it has a lot of deletion. (even if nothing changes, my thought is it deletes ev