I have a requirement to get the invalid active rule ID from the rule table for the interface errors
Interface has the logic to log an error, if more than 1 rule found for same combination of product, location and carrier.
The error log is monitored by business users and they would like to see invalid rule on the error report, so they can go and correct those.
This is my Input:
- Error Table is in SQL database, we do the Excel data query and send the below table information to users.
ID | Source | Product | Location | Carrier | Date | Error Msg |
1 | VMI | EX_0 | EX_A | EX_ABC | Jan-15 | More than 1 Active Rule found for this combination |
2 | VMI | EX_1 | EX_B | EX_XYZ | Jan-15 | More than 1 Active Role found for this combination |
End User Expecting Output like this, invalid Rule to be added on the error report.
ID | Source | Product | Location | Carrier | Date | Error Msg | Invalid ID |
1 | VMI | EX_0 | EX_A | EX_ABC | Jan-15 | More than 1 Active Role found for this combination | 1 |
2 | VMI | EX_1 | EX_B | EX_XYZ | Jan-15 | More than 1 Active Role found for this combination | 3 |
I need to look 2 different tables to get invalid rule ID for the same product, location and carrier combination.
- Cross –Reference table (this table has the corresponding internal ID’s for the external value from the error table) source is the common field in error table and the cross reference table.
ID | Source | External Value | Internal Value | Internal ID |
1 | VMI | EX_0 | IN_Pen | 001 |
2 | VMI | EX_1 | IN_Pencil | 002 |
3 | VMI | EX_A | IN_NJ | 101 |
4 | VMI | EX_B | IN_CA | 102 |
5 | VMI | EX_ABC | IN_PILOT | 201 |
6 | VMI | EX_XYZ | IN_LITER | 202 |
- After getting all the required Internal ID, I am executing below query to find out invalid rule.
SELECT ID
FROM dbo.Rule r
WHERE r.Status='Active'
AND r.productID= 001
AND r.LocationID= 101
AND r.CarrierID= 201
AND‘Jan-15’ NOT between From_Date and To_Date
Result:
ID |
1 |
Rule Table
ID | Product ID | Location ID | Carrier ID | Status | From Date | To Date |
1 | 001 | 101 | 201 | Active | Jan 14 | Dec 14 |
2 | 001 | 101 | 201 | Active | Jan 15 | Dec 15 |
3 | 002 | 102 | 202 | Active | Jan 14 | Dec 14 |
4 | 002 | 102 | 202 | Active | Jan 15 | Dec 15 |
Currently I am running these query’s manually to find the out the rule id and informing to users to correct them.
Please let me know if this is not clear.