Function to return the SQL Build Number

,

This function returns the SQL Build Number as a nvarchar(20) string. i.e. '8.00.760' @@Version is great, but super long, and the formatting of the string has changed over the years. This helps me find out what build 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].[fnGetSQLBuild]') AND xtype in (N'FN', N'IF', N'TF'))
	DROP FUNCTION [dbo].[fnGetSQLBuild]
GO

CREATE FUNCTION [dbo].[fnGetSQLBuild] () RETURNS nvarchar(20) AS
BEGIN
	RETURN SUBSTRING(@@VERSION, CHARINDEX( N' - ', @@VERSION)+3, CHARINDEX(N' (', @@VERSION) - (CHARINDEX( N' - ', @@VERSION)+3))
END

Rate

5 (1)

Share

Share

Rate

5 (1)