Technical Article

Function to return the SQL Version Number

,

This function returns the SQL Build Number as an int. i.e. 7, 8, or 9. @@Version is great, but super long, and the formatting of the string has changed over the years. This helps me find out what version of SQL I'm working on in a quick and efficient manner. The script includes the drop statement as well. Should work in all versions of SQL (Tested in SQL 2000 8.x and SQL 2005 9.x).

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[fnGetSQLVerNumber]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION [dbo].[fnGetSQLVerNumber]
GO

CREATE FUNCTION [dbo].[fnGetSQLVerNumber] () RETURNS int AS
BEGIN
RETURN SUBSTRING(@@VERSION, CHARINDEX( N' - ', @@VERSION)+3,1)
END

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating