I have a new project and just need some advice on how to do it efficiently and fast.
I have a table with about 100,000 rows with about 50 to 60 fields. It is indexed and has a primary key. The primay key in this case is a barcode.
I have to create a query that goes through each row and check for rules at each step.
For example the first rule is checking if digit 3 of the primary key is 0. So code wise it would be SUBSTRING(PkgBarcode, 3, 1) = 0
If this rule fails, I’d like to print out a message.
Also regardless if this rule fails or passes, I’d like to continue on because the rules are not dependent on each other, ie it might fail rule 2 but pass rule 3 which is okay.
I am seeking best design practices. Would it be efficient to just use select statements with print messages or some sort of loop?
How would you do this fast and efficiently?
You don’t want to do this “through each row” but rather with standard set theory. For example, you could add a BIT column for each test you need to run, and then run a query to update that bit based on the test:
That makes it easy to pull a list of the ones that do not meet a certain test while avoiding a cursor.