I'm trying to parse a sort of big SQL script containing commands like create functions and store procedures. I want to split the file in strings whenever I find a GO statement (I want to execute it using ordinary ado.net instead of SMO).
The problem is that I haven't find a suitable regular expression for that so far. Using a simple \bGO\b
ignoring case will split it. But will also split all go(s) inside a comment like
-- this go will also be split
Using this expression ^\bGO\b[^--]$
almost solve my problem but I get some error when I have two consecutive GOs (that for whatever reason are there and are behind my domain).
end
go
GO
This is how the end of a SP creation looks like in my script.
I'm doing it in C#
Thanks a lot
** EDIT **
A co-worker came up with a solution that, for now, worked for all my scripts
^\s*go\s*\r\n
^\bGO\b[^--]$
really work, or is there a typo? I think you may want to avoid--
before GO, not after. – MarashioGO
inside a string literal,/*
quotes, etc, you will need to do the equivalent of building a complete SQL parser. – Transfinite