判斷 SQL Server 版本

DECLARE @ver varchar(2) SET @ver=LEFT(CONVERT(varchar(20),SERVERPROPERTY(‘ProductVersion’)),CHARINDEX(‘.’,CONVERT(varchar(20),SERVERPROPERTY(‘ProductVersion’)),1)-1) SELECT CASE WHEN @ver=’8′ THEN ‘2000’ WHEN @ver=’9′ THEN ‘2005’ WHEN @ver=’10’ THEN ‘2008’ WHEN @ver=’11’ THEN ‘2011’ END AS ProductVersion, SERVERPROPERTY(‘ProductLevel’) AS ProductLevel, SERVERPROPERTY(‘Edition’) AS Edition, SERVERPROPERTY(‘EngineEdition’) AS EngineEdition;