I have a table with strings in one column, which are actually storing other SQL Queries written before and stored to be ran at later times. They contain parameters such as '@organisationId' or '@enterDateHere'. I want to be able to extract these.
Example:
ID | Query |
---|---|
1 | SELECT * FROM table WHERE id = @organisationId |
2 | SELECT * FROM topic WHERE creation_time <=@startDate AND creation_time >= @endDate AND id = @enterOrgHere |
3 | SELECT name + '@' + domain FROM user |
I want the following:
ID | Parameters |
---|---|
1 | @organisationId |
2 | @startDate, @endDate, @enterOrgHere |
3 | NULL |
No need to worry about how to separate/list them, as long as they are clearly visible and as long as the query lists all of them, which I don't know the number of. Please note that sometimes the queries contain just @ for example when email binding is being done, but it's not a parameter. I want just strings which start with @ and have at least one letter after it, ending with a non-letter character (space, enter, comma, semi-colon). If this causes problems, then return all strings starting with @ and I will simply identify the parameters manually.
It can include usage of Excel/Python/C# if needed, but SQL is preferable.
@\w+
. In Python:matches = re.findall(r'@\w+', your_sql_string)
.name + '@example.' + domain
... but there is more ... hehe what aboutSELECT 1 FROM WHERE /* @example = 1 AND */ 1 = 1
... just use some SQL parser ...sp_execute_external_script
to process data using Python