Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. call sql scripts from others folders

call sql scripts from others folders

Scheduled Pinned Locked Moved Database
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MrKBA
    wrote on last edited by
    #1

    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)

    CHill60C L 3 Replies Last reply
    0
    • M MrKBA

      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)

      CHill60C Offline
      CHill60C Offline
      CHill60
      wrote on last edited by
      #2

      How do you determine the "version" of the database?

      M 1 Reply Last reply
      0
      • M MrKBA

        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)

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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)

        M 1 Reply Last reply
        0
        • L Lost User

          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)

          M Offline
          M Offline
          MrKBA
          wrote on last edited by
          #4

          Have you an example how to do it ? Best,

          L 1 Reply Last reply
          0
          • CHill60C CHill60

            How do you determine the "version" of the database?

            M Offline
            M Offline
            MrKBA
            wrote on last edited by
            #5

            there is a table which contains this information :) Table "TVersion" and field "FVersion"

            1 Reply Last reply
            0
            • M MrKBA

              Have you an example how to do it ? Best,

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Which of the three versions? ..but no, not for that specific scenario.

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

              1 Reply Last reply
              0
              • M MrKBA

                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)

                CHill60C Offline
                CHill60C Offline
                CHill60
                wrote on last edited by
                #7

                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=%%i

                call .\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 for script.bat

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups