SQL Server 2008 R2 - All Script Into One

Amour22015
Amour22015 used Ask the Experts™
on
Hi Experts,

This is more of a knowledge based question.

I have about 5 scripts that I would like to save as only one script, can someone help me?

Thanks for your help.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2013
Commented:
If all five scripts in the same directory you can use a dos command:
copy *.sql combined.sql

Open in new window

Scott PletcherSenior DBA
Most Valuable Expert 2018
Top Expert 2014
Commented:
That depends.  For example, do the scripts DECLARE the same variables or temp tables?  That would be an issue.  The same label name would also be an issue (unless new batches are started).  Etc.
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
If you want to run all the scripts in a preferred order then I'll recommend you to turn on the SQLCMD mode in SSMS and use the :r command to call the scripts.
SQLCMD-mode.PNG
You can even save that script and call it from command prompt using the SQLCMD utility:
SQLCMD -E -dDatabaseName -ic:\Scripts\MainScript.sql
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I should have mentioned that all I want to do is SAVE all scripts into one.
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
I think everyone understood what you want and Chauu gave you a good solution to achieve that but ScottPletcher alerted you for some issues that can happen with that solution so I gave you another option to accomplish that by running all scripts each one within their own context so you can avoid the issues that you was alerted to.
I would be grateful to have this kind of support from experts.

Author

Commented:
I am grateful to have support from experts

I am knew to all this.

I thought there was an easy solution.

One of my co-workers did it so easy the last time but I forgot how to do this and don't want to ask him again.  It seems that what he did was not so complicated.

Lets make sure we are talking about the same thing?

When I save One script I do:
File>Save All
but that saves only one at a time.

I want to save all the scripts I have up in the window(s) into one so co-worker can take that script and move it into live.

I tried Chauu  and got error "Incorrect syntax near '*'.

Please help and thanks
IT Engineer
Distinguished Expert 2017
Commented:
Chaau's solution is to run in command prompt (DOS).
If you want to do it in SSMS then you need to open a new query window and go to each script and copy all lines to the new query window and then save the new query as a new script. It's a copy/paste solution where you need to do it a script at a time pasting the contents to the end of the new script.

Author

Commented:
I noticed that under "copy" it says: could not find stored procedure 'Copy'

Also I was told to make sure and take out all the "USE" out of each SPR.

Thanks for any help
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
Once again:
"Chaau's solution is to run in command prompt (DOS)." not in SQL Server Management Studio (SSMS).

Author

Commented:
This is what I am looking for but I don't remember my co-worker doing that.  I will see when he goes to bring that script into live.  Thanks for helping me.  Wanted to let you all know that I am grateful to have support from experts and am not trying to disagree only trying to understand.

Author

Commented:
Vitor,
Once again:
"Chaau's solution is to run in command prompt (DOS)." not in SQL Server Management Studio (SSMS).

I started working in computers in 1984 so I know about the DOS prompt but seems like technology has gone past me lately.  What I learn today is gone tomorrow, we should have all been paid like doctors?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial