Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 problem while writing a batch file for sql script

Author  Topic 

Ronesh
Starting Member

33 Posts

Posted - 2009-09-14 : 02:26:17
Dear all,

i have posted earlier as well regarding the creation for batch file for sql script.
i appriciate the response i got.they were quite useful.
now i am able to write a batch file that calls the .sql file.
the batch file which i created looks like

sqlcmd -U sa -P password -S servername
-i c:\scripts\storedprocedure1.sql

but now i am looking for something else.

if i uses the option -i ,I have to have storedprocedure1.sql as well in the very path i specified.
i was wondering if i can write the whole storedprocedure1 within the batch file only.
i have known about -q and -Q options as well in sqlcmd utility.
the storedprocedure1 contains 100s of lines.
when i tried to include that whole script within the -q option there was error.
i can write query of few lines only.
so what do you all suggest?

Looking for the positive response.

YellowBug
Aged Yak Warrior

616 Posts

Posted - 2009-09-14 : 06:12:48
I suggest you create the stored procedure in the database.
Then call it in your batch file like:
sqlcmd -U sa -P password -S servername -Q"exec database.dbo.storedprocedure1"

Go to Top of Page

Ronesh
Starting Member

33 Posts

Posted - 2009-09-15 : 06:36:52
Thanks for the suggestion Mr. Yellow.
But actually the query itself (storedprocedure1) is the script that is meant for the creation of storedprocedure1.
Basically i want to send update scripts like new sp creation or just an alter for the existing sp
to clients who dont know how to run these scripts.
and i have to tell them all the steps strting from to open ER,then QA and goes on.
it takes lots of time in phone.
so i decided to send them just a batch file so that they have to just double click the file and the script is updated.
any suggestion?
looking forward for the positive response.

Go to Top of Page

YellowBug
Aged Yak Warrior

616 Posts

Posted - 2009-09-15 : 06:58:33
In this case, I suggest you
- create a separate file for the sql statement
- create a batch file with the sqlcmd calls, using a relative path
- zip these into one file and specify the optional run a "setup" or "installation" program

This way you can further automate the distribution of the scripts.
And store the procedure in a source control system as is.

Hope this helps.
Go to Top of Page
   

- Advertisement -