so my task is to get a bunch of dockets from Excel and check in our company’s docket search and see if any does not have a matching address; if not, i need to remove characters from the end of the docket until i get a matching address or until ive reached 4 tries.
ie. i put in 100 dockets, all have matching addressed except ABC123-HRD and DJNDKGD3RTYH. manually done tells me that the correct docket would be ABC123 and i need to remove the “-HRD” part, the second docket even after 4 tries DJNDKGD3 i cannot find a matching address so I note that as “Unidentified”.
I want to use SQL to loop thru the list of dockets provided; if there is a match then put to a list of matched dockets; those that dont match get 1 character at the end removed and cross-checked again. In the end, there should be a list of valid dockets and a list of unidentifiable dockets after 4 tries. I am using Azure Data Studio and there are WHILE and FOR built in, maybe that’s a clue?
My SQL expertise is CTE and Window functions at best. I have been suggested via ChatGPT and other sources to use Recursive/ Cursor. I am aware SQL is not really made for looping so anything that helps answer my question is appreciated. Thank you.
chris nguyen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.