Reputation: 35557
Is it possible to transform sentences of the following form
IF OBJECT_ID('TEMPDB..#tmpX') IS NOT NULL DROP TABLE #tmpX; (1)
To the following
DROP TABLE IF EXISTS #tmpX; (2)
What I need to effectively is the following pseudo-code:
DROP TABLE IF EXISTS
I use sql-server but not interested in it's leftfield regex functionality - so will open the sql file in either notepad++ or komodo edit - so standard regex is what I'll use.
(apologies that I have no definite attempt included but my regex is very limited)
Upvotes: 0
Views: 71
Reputation: 48711
Find:
IF \w+\(['"][^#]*(#\w+)['"]\) IS NOT NULL DROP TABLE \1;
[^#]*(#\w+)
Match anything except #
more or zero times then the table name.Replace with:
DROP TABLE IF EXISTS $1;
Upvotes: 1