Forum Replies Created

Viewing 15 posts - 211 through 225 (of 4,085 total)

  • Reply To: "Frankenrows"

    Try a CROSS APPLY with a TOP(1) instead of a join.

    CREATE TABLE #Details
    (
    ID INT,
    ColumnA INT,
    ColumnB INT
    )

    CREATE TABLE #SubDetails
    (
    A INT,
    B INT
    )

    INSERT INTO #SubDetails (A, B)
    VALUES (1, NULL), (2,...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: how to select lowest value of column and corresponding date column

    kaj wrote:

    Instead of using the apply approach you can also try a reworked query, which works wth the minimal test data you provided:

    declare @v_po_history table (
    ...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Simple Query Question Help

    Your WHERE clause is evaluated for EACH RECORD.  A single record cannot both be equal to 1000 and 2000.  You need a query that looks at multiple records.  Piet's is...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Calculate field in SQL statement

    Your Excel formula is wrong.  Look at some simple examples.

    • If your previous balance is 1000 and you have no transfers in and no transfers out, the balance should still...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Calculate field in SQL statement

    Your Excel formula doesn't make sense to me.  For one thing, your Excel data isn't sorted, so your value for January is based on the value for April.  For another...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Flattening of hierarchy

    A recursive CTE is likely to be your best option.  Why are you excluding CTEs?

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Calculate field in SQL statement

    Your sample data has no relation to your expected output.  How do you expect people to get from the sample data to your expected output if they are completely disconnected...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: When value is same for the status then

    I suggest that you don't open multiple threads for the same topic.  Responses here: https://www.sqlservercentral.com/forums/topic/max-date-order-by-status

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Trying to identify groupings in events

    The purpose of the MIN/MAX is to assign a unique ID to each group.  It doesn't matter if the IDs are ordered or not, it's just a way of picking...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Trying to identify groupings in events

    You haven't given expected results, but this at least groups the records you wanted together.  The approach I took was to find the minimum booking id for each event (pick/drop)...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Is there anything equivalent to a Last() Function

    Steve Collins wrote:

    There's the LAST_VALUE function.  In order to return the "last value" (when the set is ordered by:  OVER (ORDER BY ...)) across the entire window of rows (in this...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Is there anything equivalent to a Last() Function

    CROSS APPLY requires reading the same table twice.  You can do this by only reading the table once.  It involves concatenating the order fields and the value field together (possibly...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: need help with T-sql

    Look at the LEAD() function--LAG() would also work.

    When posting sample data, you should use the {;} insert/edit code sample button to insert the script directly in your question instead of...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: No record in an UNION query

    saintor1 wrote:

    UNION ALL didn't achieve what I am looking for.  Please see attachment.  There are two warehouses,  S0 and LU.    On the first line, we can see that activity...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: No record in an UNION query

    UNION does an automatic DISTINCT.  Try using UNION ALL instead.  If that doesn't answer your question, you'll need to provide sample data and expected results.  The data should be provided...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

Viewing 15 posts - 211 through 225 (of 4,085 total)