Skip to content
Advertisement

Cheapest way to assign rows in order of sequence

I have a project where I have a list of barcodes, and I need to associate them to record numbers in the correct sequence based on a second column.

My data looks like this:

And then I have another set of data like this:

Is there any cheap way to join these two data sets such that I can assign the sequence in the first table based on the second? It is really arbitrary which barcode gets assigned first, as long as it is the correct barcode type. I have already done a cursor and it was way too slow.

Any suggestions? I can do my own research, just someone pointing me in the right direction would be a big help. Sorry for poor formatting.

Advertisement

Answer

If I understand correctly you can use row_number():

This type of logic can be incorporated into an update if you need to assign the value. However, the syntax for that depends on the database you are using.

EDIT:

The update in SQL Server would be:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement