call sql scripts from others folders
-
I have to do an upgrade of MSSQL database like this : I have folders that each contain an sql script I must have a sql or batch script that allows me to upgrade my database by running scripts that exist in these folders depending on the version of the current database: Example: folders 1 Folder has the name: v2.00 2 Folder has the name: v3.00 3 Folder has the name: v4.00 the initial version of the database: v3.00 the version of the final database: v4.00 So I have to have a script (or batch) that allows me to: execute just the proper scripts (in this case v3.00 and v4.00)
-
I have to do an upgrade of MSSQL database like this : I have folders that each contain an sql script I must have a sql or batch script that allows me to upgrade my database by running scripts that exist in these folders depending on the version of the current database: Example: folders 1 Folder has the name: v2.00 2 Folder has the name: v3.00 3 Folder has the name: v4.00 the initial version of the database: v3.00 the version of the final database: v4.00 So I have to have a script (or batch) that allows me to: execute just the proper scripts (in this case v3.00 and v4.00)
-
I have to do an upgrade of MSSQL database like this : I have folders that each contain an sql script I must have a sql or batch script that allows me to upgrade my database by running scripts that exist in these folders depending on the version of the current database: Example: folders 1 Folder has the name: v2.00 2 Folder has the name: v3.00 3 Folder has the name: v4.00 the initial version of the database: v3.00 the version of the final database: v4.00 So I have to have a script (or batch) that allows me to: execute just the proper scripts (in this case v3.00 and v4.00)
khaliloenit wrote:
I must have a sql or batch script
In that case you'll need to write one. You could try to do it completely from SQL, but that requires the
xp_cmdshell
sproc. Alternatively you write a batch-file for DOS, executing your scripts using the isql command. Easiest way might be a powershell-script.Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)
-
khaliloenit wrote:
I must have a sql or batch script
In that case you'll need to write one. You could try to do it completely from SQL, but that requires the
xp_cmdshell
sproc. Alternatively you write a batch-file for DOS, executing your scripts using the isql command. Easiest way might be a powershell-script.Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)
-
I have to do an upgrade of MSSQL database like this : I have folders that each contain an sql script I must have a sql or batch script that allows me to upgrade my database by running scripts that exist in these folders depending on the version of the current database: Example: folders 1 Folder has the name: v2.00 2 Folder has the name: v3.00 3 Folder has the name: v4.00 the initial version of the database: v3.00 the version of the final database: v4.00 So I have to have a script (or batch) that allows me to: execute just the proper scripts (in this case v3.00 and v4.00)
You can use the
sqlcmd
utility from a windows batch file e.g.@ECHO OFF
FOR /F %%i IN ('sqlcmd -S YourDBInstance -Q"set nocount on;select CONVERT(DECIMAL(10,2),FVersion) from TVersion"') DO SET VNO=%%icall .\v%VNO%\script.bat
@echo done.Things to note - you'll have to insert your own information for the -S parameter - Do not put spaces around the = sign in
SET VNO=%%i
- The conversion in the query is necessary to ensure the.00
is returned correctly - you will need to substitute your script name forscript.bat