September 18, 2018 at 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
September 18, 2018 at 5:08 am
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
September 18, 2018 at 5:24 am
Rick-153145 - Tuesday, September 18, 2018 4:18 AMDon'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.
September 18, 2018 at 7:06 am
Rick-153145 - Tuesday, September 18, 2018 4:18 AMDon'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
September 18, 2018 at 10:26 am
DesNorton - Tuesday, September 18, 2018 7:06 AMRick-153145 - Tuesday, September 18, 2018 4:18 AMDon'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
ENDOn 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?
September 18, 2018 at 12:23 pm
NikosV - Tuesday, September 18, 2018 10:26 AMDesNorton - Tuesday, September 18, 2018 7:06 AMRick-153145 - Tuesday, September 18, 2018 4:18 AMDon'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
ENDOn a busy system this will not prevent duplicates
Read this post from Gail Shaw
http://source.entelect.co.za/why-is-this-upsert-code-brokenDes 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