I have this SQL file with the CREATE statements for 697 stored procedures in it, but unfortunately it won't execute due to a syntax problem.
The script requires a GO
statement between every CREATE PROCEDURE
call.
The question is: how do I add GO
before every CREATE PROCEDURE
statement?
I am looking to achieve this through the use of PowerShell code.
The Select-String
might guide us in the right direction as it is able to find the 697 stored procedures in the SQL file. The below returned a count of 697. But not sure how to use this to add text in front of every finding.
(Select-String -Path $sqlFile -Pattern "CREATE PROCEDURE" -AllMatches).Matches.Count
I also tried to replace text in the file with the below command
(Get-Content $sqlFile).replace('CREATE PROCEDURE', ' GO CREATE PROCEDURE') | Set-Content $sqlFile
This however resulted in an error when executing the SQL script:
A fatal scripting error occurred. Incorrect syntax was encountered while parsing GO
Thank you for the help.