Link to home
Start Free TrialLog in
Avatar of hidrau
hidrauFlag for Brazil

asked on

how to make a condiction with mssql version?

Hello guys

I have a script that I need to run in my clients but some of them have the mssql 2005 and others mssql 2014

I need to make something this:

if mssql_version = 2005 begin
   
end else if mssql_version = 2008 begin

end else if mssql_version = 2014 begin

end;


Thanks
alexandre
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

please provide full code...Please provide the script also.
Avatar of hidrau

ASKER

For examplo, this code doesn't work in 2014, then I need to change it to another way. But for 2008 and 2005 it works fine.

if exists (select * from Master..sysdatabases where Name = '<BANCO>') begin
 use Hermes;

 exec sp_dboption 'Hermes', 'trunc. log on chkpt' , 'on';
 exec sp_dboption 'Hermes', 'select into/bulkcopy', 'on';
 exec sp_dboption 'Hermes', 'ANSI null default'   , 'on';

 --removido o autoshrink para não alterar o tamanho do banco de dados
 exec sp_dboption 'Hermes', 'autoshrink'          , 'off';
 exec sp_dboption 'Hermes', 'auto update statistics', 'off';

 --trunca as informações do arquivo de log para reduzir o tamanho
 if dbo.fnSQL_VersaoMaiorSQL() < 10  begin
 	exec('BACKUP LOG Hermes WITH TRUNCATE_ONLY');
    
    use master;
    if (select value from sysconfigures where config = 106) < 50000 begin
    	exec sp_configure 'min server memory',20;
    	exec sp_configure 'locks',50000;
    	reconfigure with override; 
     end; 
 end;
 use Hermes;
end;
go

Open in new window

Please try like--

IF mssql_version = 2005 or mssql_version = 2008
BEGIN
	
	if exists (select * from Master..sysdatabases where Name = '<BANCO>') begin
	 use Hermes;

	 exec sp_dboption 'Hermes', 'trunc. log on chkpt' , 'on';
	 exec sp_dboption 'Hermes', 'select into/bulkcopy', 'on';
	 exec sp_dboption 'Hermes', 'ANSI null default'   , 'on';

	 --removido o autoshrink para não alterar o tamanho do banco de dados
	 exec sp_dboption 'Hermes', 'autoshrink'          , 'off';
	 exec sp_dboption 'Hermes', 'auto update statistics', 'off';

	 --trunca as informações do arquivo de log para reduzir o tamanho
	 if dbo.fnSQL_VersaoMaiorSQL() < 10  begin
 		exec('BACKUP LOG Hermes WITH TRUNCATE_ONLY');
    
		use master;
		if (select value from sysconfigures where config = 106) < 50000 begin
    		exec sp_configure 'min server memory',20;
    		exec sp_configure 'locks',50000;
    		reconfigure with override; 
		 end; 
	 end;
	 use Hermes;
	end;

END;
ELSE 
BEGIN

	 

END;

Open in new window

Avatar of hidrau

ASKER

Does this exist  "mssql_version" ?

Mensagem 207, Nível 16, Estado 1, Linha 1
Invalid column name 'mssql_version'.
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hidrau

ASKER

thanks friend for your help
Avatar of hidrau

ASKER

it was to explit the point and it didn't happen. :(

Sorry Pawn :((
No problem, you can ask the moderators to open the question for you and then you can re close the question.

There is a report question link at the top of the question. You need to click on that and then you can ask the mods to open this for you.
Avatar of hidrau

ASKER

thansk for the clue Pawan
Avatar of hidrau

ASKER

Thanks a lot for your help