Forum Replies Created

Viewing 15 posts - 1,651 through 1,665 (of 2,171 total)

  • RE: DELETE all records except most recent

    Oh, but then you need to learn to read execution plans, right?

     


    N 56°04'39.16"
    E 12°55'05.25"

  • RE: DELETE all records except most recent

    Yes, you get the same execution plan.

    But still, you have to do a JOIN which means you get an extra, depending on index, index seek/scan or table scan.

     


    N 56°04'39.16"
    E 12°55'05.25"

  • RE: DELETE all records except most recent

    Well, Jeff has a CROSS JOIN, so there is a little performance penalty.

     


    N 56°04'39.16"
    E 12°55'05.25"

  • RE: DELETE all records except most recent

    DELETEt1

    FROM(

    SELECTROW_NUMBER() OVER (PARTITION BY AccountNo ORDER BY MyDateTime DESC) AS RecID

    FROMTable1

    ) AS t1

    WHERERecID > 1

     


    N 56°04'39.16"
    E 12°55'05.25"

  • RE: Deleting Duplicate Records

    Or, if you use SQL Server 2005,

     

    DELETEt1

    FROM(

    SELECTROW_NUMBER() OVER (PARTITION BY Col1 ORDER BY Col2 DESC) AS RecID

    FROMTable1

    ) AS t1

    WHERERecID > 1

     


    N 56°04'39.16"
    E 12°55'05.25"

  • RE: SQL puzzle

    His professor will notice that the code is not written by him.

    It is out of his style, if he needs to question for help.

    I know some of my occasional students...


    N 56°04'39.16"
    E 12°55'05.25"

  • RE: SQL puzzle

    Hey, you know me...

    At least I didn't write

    sp_msforeachdb 'drop database ''?''' or similar.

     


    N 56°04'39.16"
    E 12°55'05.25"

  • RE: SQL puzzle

    -- Prepare sample data

    DECLARE @Emp1 TABLE (Emp INT)

    INSERT @Emp1

    SELECT 101 UNION ALL

    SELECT 102 UNION ALL

    SELECT 103 UNION ALL

    SELECT 104

    DECLARE @Emp2 TABLE (Emp INT)

    INSERT @Emp2

    SELECT 101 UNION ALL

    SELECT 102...


    N 56°04'39.16"
    E 12°55'05.25"

  • RE: SQL puzzle

    There are at least three SET-BASED methods you can use

    1) FULL JOIN

    2) UNION ALL with GROUP BY

    3) UNION ALL with LEFT JOIN

     


    N 56°04'39.16"
    E 12°55'05.25"

  • RE: Select Question, multiple rows into one row

    -- Prepare sample data

    DECLARE

    @Sample TABLE (ClientID INT, PaySourceID INT,


    N 56°04'39.16"
    E 12°55'05.25"

  • RE: Creating a calculated boolean colum using CharIndex results

    Select CASE WHEN CharIndex('Offset', Description) > 0 THEN 1 ELSE 0 END As IsOffset From etc Where etc Order By IsOffset

     


    N 56°04'39.16"
    E 12°55'05.25"

  • RE: CAST varchar to int

    SELECT

        CAST(LEFT(DataRow, PATINDEX('%[^0-9]%', DataRow) - 1) AS bigint) AS QuestionNo

        ,CAST(SUBSTRING(DataRow, PATINDEX('%[^0-9]%', DataRow) + 1, 8000) AS bigint) AS AnswerNo

    FROM (

            SELECT '02245A555115555155' AS DataRow

        ) AS YourTable

     


    N 56°04'39.16"
    E 12°55'05.25"

  • RE: Creating a calculated boolean colum using CharIndex results

    Don't apologize. You and me are onthe same track.

    We only have to convince Gary.

     


    N 56°04'39.16"
    E 12°55'05.25"

  • RE: Creating a calculated boolean colum using CharIndex results

    I thought I was crystal clear, super green, in my answer.

     


    N 56°04'39.16"
    E 12°55'05.25"

  • RE: Delete

    CREATE PROCEDURE dbo.uspDeleteWithProjectID

    (

    @ProjectID INT

    )

    AS

    DELETE TableA WHERE ProjectID = @ProjectID

    DELETE TableB WHERE ProjectID = @ProjectID

    DELETE TableC WHERE ProjectID = @ProjectID

     


    N 56°04'39.16"
    E 12°55'05.25"

Viewing 15 posts - 1,651 through 1,665 (of 2,171 total)