SQL Update Query Based On Values

mrmmickle1

Well-known Member
Joined
May 11, 2012
Messages
2,461
I have two tables with the same fields. One is named PendingErrors and the other is named PendingImportBilling.

The fields are as follows:

Excel 2012
A
1Accession ID
2Payor Name
3Error Date
4Error Code
5Error Code Description
6Patient First Name
7Patient Last Name
8Patient DOB
9Patient Home Phone
10Insured Home Phone
11Client Billing Phone
12Note
13Client ID
14Client Name
15Subscriber ID
16Insured SSN
17Patient SSN
18Patient Full Address
19Responsible
20Category
21Type

<colgroup><col style="width: 25pxpx"><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1



I want to update the PendingErrors Table with only records that do not already exist in it.

BEFORE EXAMPLES

ie. Pending Errors:
Excel 2012
AB
1Accession IDPayor Name
21111AAA
322222AAA
433333AAA

<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1



PendingImportBilling:

Excel 2012
AB
8Accession IDPayor Name
91111BBB
1022222BBB
1133333BBB
1244444BBB
1355555BBB
1466666BBB

<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1



Pendingerrors After SQL Query:

Excel 2012
AB
1Accession IDPayor Name
21111AAA
322222AAA
433333AAA
544444BBB
655555BBB
766666BBB

<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1



I would like to insert only the records that do not currently have an Accession ID in Pending Errors. I would like the entire record (With ALL Fields) inserted into PendingErrors. Not just the Payor Name likein the simplified example.

If someone could help me out it would be much appreciated!

Thanks for looking at my issue.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
How about write/create with the wizard a query that filters out the Accession ID, then update from that? You can compare the SQL and merge them into one.
 
Upvote 0
I'm open to suggestions. Right now I have all of this written into an Excel File.

1. A User Picks Reference File 1
2. A User Picks Reference File 2
3. The Program Cleans/Filters/Manipulates the data in Excel to my database format
4. The Program Imports the Data into PendingImportBilling
5. Query 1 is run : Query to Delete Records from PendingErrors that are not in PendingImportBilling
6. Query 2 is run : Query that updates data that may have changed in Records that are in both Tables
7. This is where I am now.
 
Upvote 0
Code:
INSERT INTO PendingErrors ( ID, AccessionID, PayorName )
SELECT PendingImportBilling.ID, PendingImportBilling.AccessionID, PendingImportBilling.PayorName
FROM PendingImportBilling;


worked on your sample (even though it gave me error messages), just an append query with the wizard and design view. It's not an update query, you're adding new records rather than changing what exists.
 
Last edited:
Upvote 0
Sheetspread,

Thank you for your effort. I was able to build on your example to finish the query. I appreciate the guidance.

Code:
INSERT INTO PendingErrors
SELECT MYSELECT.*
FROM (SELECT [Accession ID], [Payor Name], [Error Date], [Error Code], [Error Code Description], [Patient First Name], [Patient Last Name], [Patient DOB], [Patient Home Phone], [Insured Home Phone], [Client Billing Phone], [Note], [Client ID], [Client Name], [Subscriber ID], [Insured SSN], [Patient SSN], [Patient Full Address], [Responsible], [Category], [Type], [Pending_Days] FROM PendingImportBilling WHERE [Pending_Days] <> 0)  AS MYSELECT LEFT JOIN PendingErrors ON MYSELECT.[Accession ID] = PendingErrors.[Accession ID]
WHERE (((PendingErrors.[Accession ID]) IS NULL));
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,039
Members
449,063
Latest member
ak94

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top