February 1, 2017 at 4:42 pm
Hi,
Does anyone have a program or utility that can merge multiple .sql files in the windows directory in to one single executable .sql file for fast deployment?
Scenario....
I have multiple .sql files: e.g.
file1.sql
file2.sql
file3.sql
fileN.sql
Which I would like to merge in to one single file e.g.
Files.sql
Thanks,
Lewis
February 1, 2017 at 5:25 pm
lewisdow123 90045 - Wednesday, February 1, 2017 4:42 PMHi,Does anyone have a program or utility that can merge multiple .sql files in the windows directory in to one single executable .sql file for fast deployment?
Scenario....
I have multiple .sql files: e.g.
file1.sql
file2.sql
file3.sql
fileN.sqlWhich I would like to merge in to one single file e.g.
Files.sqlThanks,
Lewis
Another option - I've usually done those by just creating another main sql script that has the scripts to run a sqlcmd script. Create a script that does something like:
:r c:\ScriptsDirectory\file1.sql
:r c:\ScriptsDirectory\file2.sql
:r c:\ScriptsDirectory\file3.sql
:r c:\ScriptsDirectory\file4.sql
And then just execute the main script from the command line with sqlcmd with the input being the main script. Or use sqlcmd mode in SSMS
It's kind of nice to know how to do that in general. And especially if you get a lot of sql scripts for deployments.
You can find better examples if you search on execute all sql scripts in a folder (or directory).
Sue
February 1, 2017 at 8:04 pm
lewisdow123 90045 - Wednesday, February 1, 2017 4:42 PMHi,Does anyone have a program or utility that can merge multiple .sql files in the windows directory in to one single executable .sql file for fast deployment?
Scenario....
I have multiple .sql files: e.g.
file1.sql
file2.sql
file3.sql
fileN.sqlWhich I would like to merge in to one single file e.g.
Files.sqlThanks,
Lewis
So you don't mind running files 3 and 4 if 2 fails without causing an abort?
--Jeff Moden
Change is inevitable... Change for the better is not.
February 1, 2017 at 10:55 pm
You can create a batch file that will merge them for you.
Create a file called SomeName.BAT
Add the following content, and then simply Double-Click the .BAT file
@ECHO OFF
CLS
rem Navigate to the folder
CD C:\Folder1\MyFilesSAreHere
rem Declare and set the dest file name
rem NOTE: No whitespace between variable name and value !!!!
SET %%dst=Files.sql
rem Note the single ">" to create a new file
rem A double ">>" will append to an existing file
@ECHO. > %%dst
rem Loop through a csv list of files (in the current folder)
FOR %%f IN (File1.sql,File2.sql,File3.sql,FileN.sql) DO (
rem I like to put 2 blank lines followed by a header and separator before the contents of each file.
@ECHO. > %%dst
@ECHO. > %%dst
@ECHO -- Contents of file: %%f >> %%dst
@ECHO --======================================================================= >> %%dst
rem Pipe the contents of the current file into the destination file
TYPE %%f >> %%dst
)
February 2, 2017 at 1:48 am
Thank you to all.
I think my preferred method will be with the .bat file however....
Is there a way I can loop with out having to name the filename directly?
FOR %%f IN (File1.sql,File2.sql,File3.sql,FileN.sql) DO (
Reason being is that there could be many many files...
Thank you
February 2, 2017 at 1:57 am
Could just keep it simple and do
CD C:\MyScripts\
COPY *.sql > BigScript.sql
February 2, 2017 at 3:08 am
lewisdow123 90045 - Thursday, February 2, 2017 1:48 AMThank you to all.I think my preferred method will be with the .bat file however....
Is there a way I can loop with out having to name the filename directly?
FOR %%f IN (File1.sql,File2.sql,File3.sql,FileN.sql) DO (Reason being is that there could be many many files...
Thank you
There probably is, but I'm afraid I have only figured out how to do it with a fixed list
February 2, 2017 at 6:58 am
FOR %%f IN (*.sql) DO ....
Far away is close at hand in the images of elsewhere.
Anon.
February 2, 2017 at 7:54 am
David Burrows - Thursday, February 2, 2017 6:58 AMFOR %%f IN (*.sql) DO ....
They have an even easier method now...
https://technet.microsoft.com/en-us/library/cc753551(v=ws.11).aspx
--Jeff Moden
Change is inevitable... Change for the better is not.
February 2, 2017 at 8:12 am
Jeff Moden - Thursday, February 2, 2017 7:54 AMDavid Burrows - Thursday, February 2, 2017 6:58 AMFOR %%f IN (*.sql) DO ....
They have an even easier method now...
https://technet.microsoft.com/en-us/library/cc753551(v=ws.11).aspx
Far away is close at hand in the images of elsewhere.
Anon.
February 3, 2017 at 5:50 pm
Hi All,
Thank you for your replies.
I tried this but it did not work.
Any help would be very much appreciated.
@ECHO OFF
CLS
rem Navigate to the folder
CD C:\FileLocation\
rem Declare and set the dest file name
rem NOTE: No whitespace between variable name and value !!!!
SET %%dst=Files.sql
rem Note the single ">" to create a new file
rem A double ">>" will append to an existing file
@ECHO. > %%dst
rem Loop through a csv list of files (in the current folder)
FOR %%f IN (*.sql) DO (
rem I like to put 2 blank lines followed by a header and separator before the contents of each file.
@ECHO. > %%dst
@ECHO. > %%dst
@ECHO -- Contents of file: %%f >> %%dst
@ECHO --======================================================================= >> %%dst
rem Pipe the contents of the current file into the destination file
TYPE %%f >> %%dst
)
PAUSE
February 7, 2017 at 2:27 am
Change drive as well as folder
Some of your parameter substitutions are wrong
Some of your redirections are wrong
Do not put output file (with .sql extension) in same folder as it will be included and your output will be duplicated
@ECHO OFF
CLS
rem Navigate to the folder
C:
CD C:\FileLocation\
MD C:\FileLocation\Output
rem Declare and set the dest file name
rem NOTE: No whitespace between variable name and value !!!!
SET dst=Output\Files.sql
rem Note the single ">" to create a new file
rem A double ">>" will append to an existing file
@ECHO. > %dst%
rem Loop through a csv list of files (in the current folder)
FOR %%f IN (*.sql) DO (
rem I like to put 2 blank lines followed by a header and separator before the contents of each file.
@ECHO. >> %dst%
@ECHO. >> %dst%
@ECHO -- Contents of file: %%f >> %dst%
@ECHO --======================================================================= >> %dst%
rem Pipe the contents of the current file into the destination file
TYPE %%f >> %dst%
)
Far away is close at hand in the images of elsewhere.
Anon.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy