Skip to content
Advertisement

How do I insert a row into a table where one column has the next character on the ascii table for the next 11 available characters?

I am new at SQL (know enough to be dangerous but not enough to do elegant code) I am working with an existing database and they had used ascii characters as unique identifiers.For example:

I am trying to find a way to write a script that will add the next row to a table that has the next available ascii character. Due to the nature of the database, I cannot change how it is set up.

I have tried Googling things like:

Most of the results are to just see the next ascii character.

I have tried finding a way of just creating a temp table of all the ascii characters and then removing the ones that already exist, filling in the 11 rows with the information that needs to be added then stop when the next row would have a null for the description.

I found posts like create a list of the alphabet via SQL

But still cannot figure out how to add to the existing or create the temp table.

–I know that this is EXTREMELY novice and messy but I am trying to piece it together with chunks of code from various sources on the internet.

Ideally I would like to be able to add the rows directly to the table but am willing to add the information to a temp table and then copy it to the actual table. Outside of brute forcing it by creating a table will all the ascii values and deleting the ones that already exist, I am at a loss.

Advertisement

Answer

How does this work for you? May not be a complete answer but it’s a start (and I can update this post accordingly.)

Another way (using a temp table for a demo you can copy/paste run)…

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