Recognising the SQL Server Version
Something I often need to do is recognise which SQL Server version I am working on. For example to separate SQL 2000 compatible code from SQL Server 2005 compatible code. I'll show you some of the options to get the version number... Starting from the ugliest to the most elegant... The first option is calling the extended procedure xp_msver
exec xp_msver 'ProductVersion'
Index | Name | Internal_Value | Character_Value |
---|---|---|---|
2 | ProductVersion | 524288 | 8.00.2039 |
select @@version
Microsoft SQL Server 2005 - 9.00.3054.00 (Intel X86) Mar 23 2007 16:28:52 Copyright (c) 1988-2005 Microsoft Corporation Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 2) |
select serverproperty('productversion')
9.00.3054.00 |
select @@microsoftversion / 0x01000000
9 |
SELECT CASE @@microsoftversion/ 0x01000000 WHEN 8 THEN 'sql 2000' WHEN 9 THEN 'sql 2005' WHEN 10 THEN 'sql 2008' END
No comments:
Post a Comment