Avoid duplicate values

  • Don't know what Premium is as you give no context, so if its important, add it to the query, else:

    IF EXISTS (SELECT 1 FROM BR_LIMIT_INSURANCES_TEST_TWO A INNER JOIN @excelTableType B ON B.Branch = A.Branch AND A.ReportMonth = @month AND A.ReportYear = @year)
    BEGIN
       ---Do Update
    END
    ELSE
    BEGIN
    --Do Insert
    END

  • Rick I'm having trouble writing out the update.

    I basically want to say update SET A.Field = B.Field WHERE A.ReportMonth = @month but I can't get it to work.
    Could you help on the update condition please?

    Thanks

  • Rick-153145 - Tuesday, September 18, 2018 4:18 AM

    Don't know what Premium is as you give no context, so if its important, add it to the query, else:

    IF EXISTS (SELECT 1 FROM BR_LIMIT_INSURANCES_TEST_TWO A INNER JOIN @excelTableType B ON B.Branch = A.Branch AND A.ReportMonth = @month AND A.ReportYear = @year)
    BEGIN
       ---Do Update
    END
    ELSE
    BEGIN
    --Do Insert
    END

    Quick update. 'Premium' is now a MONEY data type column.

  • Rick-153145 - Tuesday, September 18, 2018 4:18 AM

    Don't know what Premium is as you give no context, so if its important, add it to the query, else:

    IF EXISTS (SELECT 1 FROM BR_LIMIT_INSURANCES_TEST_TWO A INNER JOIN @excelTableType B ON B.Branch = A.Branch AND A.ReportMonth = @month AND A.ReportYear = @year)
    BEGIN
       ---Do Update
    END
    ELSE
    BEGIN
    --Do Insert
    END

    On a busy system this will not prevent duplicates
    Read this post from Gail Shaw

    http://source.entelect.co.za/why-is-this-upsert-code-broken

  • DesNorton - Tuesday, September 18, 2018 7:06 AM

    Rick-153145 - Tuesday, September 18, 2018 4:18 AM

    Don't know what Premium is as you give no context, so if its important, add it to the query, else:

    IF EXISTS (SELECT 1 FROM BR_LIMIT_INSURANCES_TEST_TWO A INNER JOIN @excelTableType B ON B.Branch = A.Branch AND A.ReportMonth = @month AND A.ReportYear = @year)
    BEGIN
       ---Do Update
    END
    ELSE
    BEGIN
    --Do Insert
    END

    On a busy system this will not prevent duplicates
    Read this post from Gail Shaw

    http://source.entelect.co.za/why-is-this-upsert-code-broken

    Des is that link for me to read or for Rick?

  • NikosV - Tuesday, September 18, 2018 10:26 AM

    DesNorton - Tuesday, September 18, 2018 7:06 AM

    Rick-153145 - Tuesday, September 18, 2018 4:18 AM

    Don't know what Premium is as you give no context, so if its important, add it to the query, else:

    IF EXISTS (SELECT 1 FROM BR_LIMIT_INSURANCES_TEST_TWO A INNER JOIN @excelTableType B ON B.Branch = A.Branch AND A.ReportMonth = @month AND A.ReportYear = @year)
    BEGIN
       ---Do Update
    END
    ELSE
    BEGIN
    --Do Insert
    END

    On a busy system this will not prevent duplicates
    Read this post from Gail Shaw

    http://source.entelect.co.za/why-is-this-upsert-code-broken

    Des is that link for me to read or for Rick?

    You both could benefit from it.

Viewing 6 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply