Forum Replies Created

Viewing 15 posts - 6,841 through 6,855 (of 10,144 total)

  • RE: Help Needed for SQL Query

    yatish.patil (7/12/2011)


    HI ChrisM@Work,

    Thank you for your query Solution, but when I tested the output for the data as below.

    ...

    You can see the difference between both. Thank you for...

  • RE: Help Needed for SQL Query

    ;WITH Calculator1 AS (

    SELECT Historyid, ID, LetterNo, letter,

    rn1 = ROW_NUMBER() OVER(ORDER BY Historyid),

    rn2 = ROW_NUMBER() OVER(PARTITION BY Letter ORDER BY Historyid)

    FROM #Test),

    Calculator2 AS (

    SELECT Historyid, ID, LetterNo,...

  • RE: Do you use Facebook?

    Facebook is awesome for retaining a link with distant relatives. I have cousins in Canada and Hong Kong (and family scattered all around the UK) and FB lets me keep...

  • RE: String to Paragraph.

    Here's another APPLY solution:

    DROP TABLE #Strings

    CREATE TABLE #Strings (Longstring VARCHAR(150))

    INSERT INTO #Strings (Longstring) values ('SABRE a CIRCUIT BREAKER MOTORISATION SCHEMATIC DIAGRAM, FOR USE WITH MICOM & A MULTI VOLTAGE SHUNT...

  • RE: Today's Random Word!

    Daniel Bowlin (7/11/2011)


    falling behind

    It's all going South sooner or later.

  • RE: SQL Update Behaviour

    John Mitchell-245523 (7/7/2011)


    ... the value will be updated with all the values, leaving the one that was done last as the value that persists...

    From BOL UPDATE section: "...This is because...

  • RE: Running total (cummulative Sum)

    SQLkiwi (7/7/2011)


    ... By the way, a windowing function in the recursive part of a CTE has a weird semantic (quite counter-intuitive, in fact) but works the way it does because...

  • RE: Running total (cummulative Sum)

    SQLkiwi (7/7/2011)


    Hi Chris,

    There's no need for a join at all - a point I realised after editing the TOP trick into your code. I have updated the code and...

  • RE: Running total (cummulative Sum)

    The new version runs faster but not by much.

    So the optimizer converts what looks like a triangular join (the entire CROSS APPLY part) into a TOP query?

    Interestingly, you can...

  • RE: Running total (cummulative Sum)

    Nice one, Paul. The triangular join put me off writing and testing it, but in practice the performance is stunningly good - half a million rows return in 12s on...

  • RE: Running total (cummulative Sum)

    Craig Farrell (7/6/2011)


    Jeff Moden (7/6/2011)


    Chris,

    Do you know of a way to use the rCTE to do a running total without the ID's being perfectly sequential?

    There's a way using Cross Apply...

  • RE: Running total (cummulative Sum)

    tommey152 (7/6/2011)


    Hi ,

    .....

    Is there any SQL statement that can do this easily? What's the best way to accomplish this?

    Easiest is the recursive CTE:

    DROP TABLE #SourceData

    CREATE TABLE #SourceData (id INT...

  • RE: where condition parameter

    -- simplest

    SELECT *

    FROM t

    WHERE YEAR(CASE

    WHEN t.[type] = 'import' THEN t.arrdate

    WHEN t.[type] = 'export' THEN t.depdate

    ELSE NULL END) = YEAR(@deparr)

    -- possibly faster

    SELECT *

    FROM t...

  • RE: Today's Random Word!

    Today's Random World: "Dragon's Egg".

  • RE: Join to at least one record as default

    SQLkiwi (6/30/2011)


    ChrisM@Work (6/30/2011)


    ...code...

    Hi Chris,

    You might be interested in a slight tweak to that code. Take a look at the query plans for these:

    ...

    Notice the special distinct sort in the...

Viewing 15 posts - 6,841 through 6,855 (of 10,144 total)