Forum Replies Created

Viewing 15 posts - 256 through 270 (of 4,085 total)

  • Reply To: UPDATE statement on CTE with INNER JOIN

    You're UPDATE statement is incorrect.  If you are going to alias something, you need to use that alias throughout.

    UPDATE o -- use the alias here.
    SET o.Description =...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Group by the messages based on the Column and retrieve the records

    A picture of your data is worthless.

    1. You need to provide a script using the {;} Insert/edit code sample that does the following.

      1. Creates a temp table or declares a...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: i get error All queries combined using a UNION, INTERSECT or EXCEPT operator mus

    Your "header" row has five columns, but your details rows have eight.  Without knowing what your final goal is, it's hard to tell you the best way to resolve this...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Help with SUM/GROUP BY issue

    This is much more efficient.  Note that it has a windowed function SUM() OVER() of an aggregate SUM().

    SELECT
    per
    ,company
    ,account
    ,COUNT(*) AS accNum
    ,SUM(amount) as accTotals
    ,SUM(SUM(amount)) OVER(PARTITION BY per, company) as...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Need to replace this inefficient CASE statement

    Jonathan AC Roberts wrote:

    I'm not sure that all the answers given in this thread are correct?

    The where clause, if indented, looks like this:

    WHERE 1 = CASE WHEN T.record_Key_4 =...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Time worked on a ticket Query

    This is a variation on packing intervals.  Itzik Ben-Gan has written a number of articles that might be helpful.  If you post consumable data I can help you with it. ...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Creating Subtotal With CTE and union

    You're doing a partial CROSS JOIN.  You either need to SUM your totals before joining or do a UNION before SUMming.  You could also use GROUPING SETS.  Since you failed...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Concat XML field values ?

    jbalbo wrote:

    Hi

    Sorry, i got caught up doing another project....

    Honestly, I "sorta"  get what's going on here,

    STUFF(
    ...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Concat XML field values ?

    Show us what you've tried and we'll help you through it.  There are a couple of ways to approach it.  I would probably start by changing what nodes are returned...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Concat XML field values ?

    I used an XML variable, but you can easily replace the variable with your field.

    SELECT STUFF(
    (
    SELECT ',', c.value('.', 'VARCHAR(20)')
    FROM @doc.nodes('/Data/Purpose_x0020_of_x0020_Request/Data_Purpose_x0020_of_x0020_Request_Option[Checked="true"]/Name') T(c)
    FOR XML PATH(''), TYPE
    ).value('.', 'VARCHAR(255)'), 1, 1,...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Count of Distinct Clients in a list, in groups

    tacy.highland wrote:

    The query you provided appears to be doing something like a running count of passengers on each event but it doesn't quite get it right.  I need just one...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Count of Distinct Clients in a list, in groups

    When you provide sample data DO NOT USE A PERMANENT TABLE. You should either provide a temp table or a table variable.

    When you provide sample data, the VALUES clause can...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Count of Distinct Clients in a list, in groups

    I see nothing in your data that indicates that you picked up 9 people at the same time/location.  There is no way to provide a solution without that field.  If...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Count of Distinct Clients in a list, in groups

    You were already given an answer to this in your previous thread.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Query to Exclude results

    EXCEPT is unlikely to be the best performing solution here, because it requires you to read the table twice and there are other solutions that should only require reading the...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

Viewing 15 posts - 256 through 270 (of 4,085 total)