I have a table where the first column contains SQL commands such as DELETE and UPDATE statements. I would like to read each row, identify the table name and column name from that row, and print them in separate columns titled "Table Name" and "Column Name" respectively.
Solved! Go to Solution.
Could you provide some samples or images to better help us understand your requirement? Not too sure what you mean....
Hi @Rao2821
You may be able to use a Text to Columns tool to separate out your statements and get the pieces you're looking for. Alternatively, RegEx may be a possibility. Could you provide a couple lines of sample data?
Hey @Kenda,
I have attached the sample data. Thank you
Hi @caltang
I have attached the sample data. Thank you.
Adding to what @Kenda has recommended, you can use a filter tool to split out the UPDATE and DELETE statements because it will be easier to REGEX for each individually and then Union the result again.
You can use a Parse tool to get what you desire from the text.
Sorry, I meant use a REGEX tool to parse out like so:
for DELETE:
For the table name: "from\s+(\w+)"
For the column names: "(?<=set\s|where\s)\w+"
for UPDATE:
For the table name: "update\s+(\w+)"
For the column names: "(?<=set\s)\w+\s*=|\w+(?=\s*where)"
Hope this helps give some ideas…
Here is an expression that you can use in a Formula tool to get the table name in the first two delete statements:
REGEX_Replace([Commands], ".*from (.*?) where.*", "$1")
The expression looks for the characters between the words "from " and the first instance of " where" and outputs what is between them (identified using parenthesis in this expression).
Try to build your own expressions to get the other pieces you're looking for!
https://regex101.com/ is a great resource to help learn RegEx.