Forum Replies Created

Viewing 15 posts - 751 through 765 (of 1,413 total)

  • Reply To: Balance is not calculating correctly,when date get change in transection.

    This is sort of confusing because the ORDER BY of the outermost query includes the 'head' column as well as 'Trans_ID'.  The SUM OVER ORDER BY is only by '(select...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Compare columns between 2 tables

    This comes really close.  It uses a FULL JOIN which is functionally both a LEFT JOIN and a RIGHT JOIN.  It seems the example Status_ToolType column might have some consistency...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Sql Joins !

    Should've hit refresh 🙂

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Sql Joins !

    Maybe the correlated subquery in the WHERE clause is converting your LEFT JOIN into an INNER JOIN.  Maybe try expressing OBS as OUTER APPLY SELECT TOP(1) ... instead.

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Spoofing Data Convincingly: Text Data

    Why call it "spoofing" and not "mocking"?  Is spoofing mocking?  Is mocking spoofing?

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Selecting last 6 months

    Instead of approximating the "current" date by selecting the MAX(date) the code could reference CAST(GETDATE() as DATE) to access the system datetime and cast it as type DATE.

  • This reply was modified 5 years, 5 months ago by Steve Collins.

Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Update Column Based on Criteria from Other Columns -- improved post included DDL

    Ugh it's dependent on calculated row values.  Although painful to create, here's a WHILE loop which populates a new table '#myNewTable' with the ID and the derived theoretical_cycle column.  It's...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Update Column Based on Criteria from Other Columns -- improved post included DDL

    Does it also restart at 0 when aggregating the days?

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Update Column Based on Criteria from Other Columns -- improved post included DDL

    The 'max_val' column matches the 'Days_Cycle' column in the table provided.  The 'theoritical_cycle' (in rows where ID is greater than 19) doesn't seem to follow the rules you're suggesting

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Update Column Based on Criteria from Other Columns -- improved post included DDL

    Integer division comes in handy when creating groupings based on ranges of integers,  aka "buckets".  Something like this

    select t.*, v.*, cycle.*
    from #mytable t
    ...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Filling in Empty Rows

    Well well, this is the first time I can recall ever using a RIGHT JOIN in a "real" query.  It seems to make sense here.

    declare @dt ...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Filling in Empty Rows

    The data looks something like this?

    drop table if exists #conditions;
    go
    create table #conditions(
    some_dt date not null,
    code ...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: How to filter out the data?

    DECLARE @v_order_id INT = 1;

    WITH
    myData AS(
    SELECT 'all_codes_set' AS code_type,
    1 AS start_id,
    100 AS end_id,
    1 AS order_id
    UNION ALL
    SELECT 'all_codes_set' AS code_type,
    101 AS start_id,
    110 AS end_id,
    2 AS order_id
    UNION...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: How to filter out the data?

    Ok, the non-tvf same approach uses an additional CTE and SELECT TOP(n).  The following code is to be embedded in the SQL to replace dbo.fnTally.  The maximum # of rows...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: How to filter out the data?

    The fastest way to reliably get an answer is not necessarily the "best" way but it's functional.  Afaik something like this would work.  It uses a tally function to expand...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Viewing 15 posts - 751 through 765 (of 1,413 total)