Forum Replies Created

Viewing 15 posts - 1,126 through 1,140 (of 1,419 total)

  • Reply To: Query Help Insert same data for multiple dates

    This uses the daterange function from this article: https://www.sqlservercentral.com/scripts/a-daterange-table-valued-function

     

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

  • Reply To: Query Help Insert same data for multiple dates

    drop table if exists #tblTest;
    go
    create table #tblTest
    (ename varchar(10),
    Amount float,
    eDate date);
    go

    insert #tblTest values
    ('ABC',615.00,'03/23/2020'),
    ('ABC',540.00,'03/23/2020'),
    ('ABC',207.00,'03/23/2020'),
    ('PQR',449.00,'03/23/2020'),
    ('PQR',1065.00,'03/23/2020'),
    ('PQR',-2435.00,'03/23/2020');

    declare
    @max_dt ...

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

  • Reply To: would like to know more about identity_cache

    Jeff Moden wrote:

    Steve Collins wrote:

    Afaik and imo there are no pros only cons.  There is no such thing as a "gap" in a primary key because 'unit consistency' is not a necessary...

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

  • Reply To: would like to know more about identity_cache

    Afaik and imo there are no pros only cons.  There is no such thing as a "gap" in a primary key because 'unit consistency' is not a necessary attribute.  Maybe...

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

  • Reply To: Get the correct output

    ScottPletcher wrote:

    I prefer to always use INNER and OUTER for clarity.

    Clarity could not also come from conciseness?  It seems to me adding extra information which is of questionable necessity adds...

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

  • Reply To: Get the correct output

    Steve and Jeff, thank you.  Good to have other eyes on this. 🙂  What should I do with the earlier incorrect code?  Wipe it out?  Should I have kept updating...

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

  • Reply To: Get the correct output

    If dupes are ok but the alerttypeid may only be in (4, 6), then maybe this works

    with only_two_cte(alertid) as (
    select
    ...

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

  • Reply To: Get the correct output

    with only_two_cte(alertid) as (
    select
    alertid
    from
    #aaa
    ...

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

  • Reply To: Get the correct output

    Ok yeah I'm starting to see the alerttypeid's should be counted separately.

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

  • Reply To: Get the correct output

    with only_two_cte(alertid) as (
    select
    alertid
    from
    #aaa
    ...

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

  • Reply To: Get the correct output

    select distinct
    first_value(alertid) over (partition by alerttypeid order by alertid desc) alertid,
    alerttypeid
    from
    #aaa
    where
    alerttypeid in(4,6);

     

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

  • Reply To: Query Help - Sum question with excluding condition

    Steve Collins wrote:

    ;with
    ordered_amounts as (
    select distinct first_value(amount) over (partition by userid order by keyid desc) amount from #t)
    select
    sum(amount) total
    from
    ordered_amounts;

    This...

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

  • Reply To: Query Help - Sum question with excluding condition

    ;with
    ordered_amounts as (
    select distinct first_value(amount) over (partition by userid order by keyid desc) amount from #t)
    select
    sum(amount) total
    from
    ordered_amounts;

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

  • Reply To: Scalar function too slow - Calculated field in column based on another columns

    Baldie47 wrote:

    I need one column for BSP between 1 and 3, one column for BSP between 3 and 5, one column for bsp between 5 and 8 (and up to...

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

  • Reply To: Scalar function too slow - Calculated field in column based on another columns

    Sometimes spreadsheets are useful to concatenate together parameterized sql code.

    ="sum(case when (td.BSP >="&B7&" and td.BSP <"&C7&") and td.WIN_LOSE=1 then td.BSP end) as SumWinnerPrice"&B7&"to"&C7
    ="count(case when (td.BSP >="&B8&" and...

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

Viewing 15 posts - 1,126 through 1,140 (of 1,419 total)