运行条件查询


0
  • 我有一个露水版系统。任何版本都有5-9升级 脚本。为了将版本1升级到5,我必须运行每个脚本 在任何版本的正确顺序(01_script,02_script, 03_script ...)如果安装的版本是01,我开始运行 从版本02开始的脚本我有一个表,其中包含也在注册表中编写的版本号的值。

我有能力获取所有脚本并将它们合并为一个脚本

我怎样才能创建一个脚本来检查版本并开始运行正确的脚本?

(sql server 2008r2)


1
例如:如果version = 01则运行脚本3,4,5 |如果版本= 02运行脚本6,7,8
Gilad Bronshtein

Answers:


0

这是可能的,但并不总是那么容易。作为后备箱:

if not exists (select * from sysobjects where name='VersionInfo' and xtype='U')
    create table VersionInfo (InstDate dateTime,[Version] int, Name varchar(64) not null)
GO    
if (Select Coalesce(Max([Version]),0) from VersionInfo) = 0
    begin   
      Print 'Your first Script'      
      EXEC('Create Table test1 (ID int)') 
      Insert into Test1 Values (1)
      insert into VersionInfo Values (GetDate(),1,'Version 1')
    end
if (Select Coalesce(Max([Version]),0) from VersionInfo) = 1
    begin   
      Print 'Your second Script'      
      EXEC('Create Table test2(ID int)') 
      insert into VersionInfo Values (GetDate(),2,'Version 2')
    end    
if (Select Coalesce(Max([Version]),0) from VersionInfo) = 2
    begin   
      Print 'Your third Script'     
      Insert into Test1 Values (1)
      insert into VersionInfo Values (GetDate(),3,'Version 3')
    end  
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.