Forum Replies Created

Viewing 15 posts - 496 through 510 (of 1,419 total)

  • Reply To: Show data that takes into consideration data of consecutive weeks

    The LAG function takes up to 3 parameters:

    1) Column name (required)
    2) Row offset (optional)
    3) Default value (optional)

    To find 3 +/- consecutive rows with the same sign maybe...

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

  • Reply To: Amazon Redshift

    Aaron N. Cutshall wrote:

    Redshift is based on an earlier version of Postgres. It was modified to be a columnar database, but it doesn't have many of nice features and functions that were...

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

  • Reply To: First Value Partition

    Suppose there's an ordinal column called 'Ord'.  The WHERE clause makes sure the "first" row is a "root" ElementID.  The OUTER APPLY selects the ElementID to substitute if the row...

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

  • Reply To: Return a list of all columns in a table with more than X % filled

    pietlinden wrote:

    Say I have a table that allows nulls on some columns. As records are added, some columns are filled only say 20% of the time. is there an easy...

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

  • Reply To: First Value Partition

    It doesn't seem possible without additional information.  In your FIRST_VALUE function the PARTITION BY patid and ORDER BY elementiddate doesn't seem to deterministically define the order of the rows where...

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

  • Reply To: drop one row based on criteria

    delete p
    from #pat p
    where p.ElementID='B'
    and exists(select 1
    ...

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

  • Reply To: drop one row based on criteria

    Maybe a DELETE statement like this. [Edit: got rid of window function approach and went with COUNT(*) ]

    with rn_cte(PatID, ElementIDDate) as (
    select PatID,...

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

  • Reply To: Need help resolving a SET based Query where I have hardcoded values

    with recent_cte(HorseName, FinishPosition, RaceDate, Rating) as (
    SELECT top 1 with ties HorseName, FinishPosition, RaceDate, Rating
    FROM @RACES
    ...

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

  • Reply To: String

    Following on what Mr. Brian Gale wrote about a DELETE causing a massive gap in the IDENTITY property of a table.  It happens sometimes because things which aren't good sometimes...

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

  • Reply To: Using If Else condition in Merge Statement : SQL

    Based on the code I would guess your ExceptionLog table is empty because the error handling issues the ROLLBACK before the error values are accessed.  But it's not really guaranteed...

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

  • Reply To: Cumulative Report

    It's a great answer from Jeff which exactly matches the output.  My approach also uses Jeff's "number generator" function dbo.fnTally.  While Jeff "didn't use any of your dates" (because it's...

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

  • Reply To: Case Statement in where

    Maybe like this

    if @ItemGroup is null
    Select Itemcode,Itemname,ItemGroup
    from tbl1
    where itemgroup is null;
    else
    Select...

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

  • Reply To: Invalid column Name Hcode

    Maybe extract the constant and put the correlated subquery in the FROM clause as a CROSS APPLY

    declare @vmax_var         ...

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

  • Reply To: help with case statement

    Maybe a good way could be an UPDATE statement

    update t
    set flag = case when v.row_count=1 then 'ANY_EMPTY'
    ...

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

  • Reply To: How to sum on one value and not to sum on another value

    In the situation where Sum([QTY]) returns the correct the number, AVG(OH) or MAX(OH) ought to return only 1 SKU

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

Viewing 15 posts - 496 through 510 (of 1,419 total)