Forum Replies Created

Viewing 15 posts - 556 through 570 (of 1,424 total)

  • Reply To: TSQL: Create dynamic partition DataRange

    Yes a calendar table is another workable approach.  What if the minDate and/or maxDate is other than the 1st or last day of the month?  Maybe something like this

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

  • Reply To: TSQL: Create dynamic partition DataRange

    Yes sorry.  It should've been included.  The code is from Jeff Moden's article here on SSC. It comes in handy in many places

    CREATE FUNCTION [dbo].[fnTally]
    /**********************************************************************************************************************
    ...

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

  • Reply To: How to make row number start by 1 instead of 0 when make union all?

    For the counting to begin at 1 maybe you could assign the value 1 to rows where the status is null.  Then UNION ALL for the additional rows with the...

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

  • Reply To: TSQL: Create dynamic partition DataRange

    There are different date calculations depending on granularity.  This seems to work

    drop table if exists #foo;
    go
    create table #foo(
    [Table] sysname,
    ...

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

  • Reply To: Grouping , time difference in minutes

    Hi Joel, maybe something like this.  It's pretty self-explanatory once you run it

    drop table if exists #foo;
    go
    create table #foo(
    [datetime] datetime,
    tonsperhour...

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

  • Reply To: trigger after update

    Maybe you're looking for something like this.  It assumes there's a primary key column in the OfenbuchVC1212_V10 table called 'OfenbuchId'.  After update of the OfenbuchVC1212_V10 table the trigger first determines...

    • This reply was modified 5 years, 1 months ago by Steve Collins. Reason: Added INSERT

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

  • Reply To: Max of 2 columns gets sent to the third column (SQL)

    [Edit] I posted some code that didn't look right so I updated.  Maybe something like this

    select w2.RCWHS# as DC, w2.RCITM# as [Item Number],
    ...

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

  • Reply To: Extracting a Median Date out of a Group of Records using a Query with NTILE

    Maybe something like this

    ;with
    cte_ntile(ReadingDateTime, ReadingValue, [Group]) AS (
    select *, ntile(2) over(order by ReadingDateTime asc) AS [Group]
    from #SIDataGroup),
    cte_rn(ReadingDateTime, ReadingValue, [Group],...

    • This reply was modified 5 years, 1 months ago by Steve Collins. Reason: Typo
    • This reply was modified 5 years, 1 months ago by Steve Collins. Reason: Simplified query: replaced UNION ALL in subquery with SELECT TOP(n)

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

  • Reply To: Extracting a Median Date out of a Group of Records using a Query with NTILE

    It turns out the median is derived from the ordered set.   My query only calculated the midpoint.  If the number of rows in the [Group] (calculated as 'grp_count') is even...

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

  • Reply To: Extracting a Median Date out of a Group of Records using a Query with NTILE

    Thanks for the feedback.  Nice I'm happy if the code helps.  Precision-wise it's maybe not ideal.  I tried it with nanoseconds and there was an overflow error.  Maybe microseconds would...

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

  • Reply To: Extracting a Median Date out of a Group of Records using a Query with NTILE

    Maybe something like this.  The 'median_dt' column calculation adds half the difference in seconds between the min and max ReadingDateTime values within the [Group] group to the min ReadingDateTime

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

  • Reply To: Calculate count of credit decision (One or multiple custom sql)

    Imo you could maybe start with a query like this.  The 'final_cte' CTE selects the row(s) with the final status for each Deal.  Then OUTER APPLY is used to count...

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

  • Reply To: Calculate count of credit decision (One or multiple custom sql)

    It's not a good logical model.  What is the maximum number of rows per Deal?  If it's 2 you could join the table to itself

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

  • Reply To: Dynamic SQL? Inserting Sproc data into table variable

    I just ran into this same issue.  The short answer is to create a #temp table instead and it works (because the temp table exists within the same execution context...

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

  • Reply To: Are the posted questions getting worse?

    Lynn Pettis wrote:

    I was off topic??

    The other comment.  Your comment was very on topic 🙂

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

  • Viewing 15 posts - 556 through 570 (of 1,424 total)