Skip to content

Instantly share code, notes, and snippets.

@dmlogv
Created July 24, 2019 06:14
Show Gist options
  • Select an option

  • Save dmlogv/836be6888b9ff5269ced3aca0c59c205 to your computer and use it in GitHub Desktop.

Select an option

Save dmlogv/836be6888b9ff5269ced3aca0c59c205 to your computer and use it in GitHub Desktop.
RegEx T-SQL Parser for extracting sources and destinations from the INSERT statement
(insert (?: \s (?:bulk|into))?) \s
(?(?=openquery) (?:
(openquery) \s \(
(\S+?) \, \s \' .+? \'\)
)
| (\S+)
)
.+?
select
(?:.+?(from|join) \s (\S+))+
(?<i_cl>insert (?: \s (?: into | bulk ))?) \s
(?(?=openquery) (?:
(?<i_oq>openquery) \s \(
(?<i_oq_srv>\S+) \, \s \'
.*?
\'\)
)
| (?:
(?<i_tbl>\S+)
)
)
.*? \s select \s .*?
(?:
(?<f_cl>from) \s
(?(?=openquery) (?:
(?<f_oq>openquery) \s \(
(?<f_oq_srv>\S+) \, \s \'
(?: .+? (?<f_oq_cl>from|join) \s (?<f_oq_tbl>\S+) )
.* \'\)
)
| (?: (?<f_tbl>\S+) )
)
)+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment