Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ALTER FUNCTION [dbo].[fn_StringToVersion] (@version NVARCHAR(255))
- RETURNS BIGINT
- AS
- BEGIN
- DECLARE @temp NCHAR
- DECLARE @minor BIGINT
- DECLARE @major BIGINT
- DECLARE @numberOfDot INT
- DECLARE @position INT
- SET @minor = 0
- SET @major = 0
- SET @numberOfDot = 0
- SET @position = 1
- SET @temp = N'0'
- WHILE @position <= LEN(@version)
- BEGIN
- SET @temp = SUBSTRING(@version, @position, 1)
- IF @temp >= N'0' AND @temp <= N'9'
- -- Building sub version
- SET @minor = @minor * 10 + ASCII(@temp) - ASCII(N'0')
- ELSE IF @temp = N'.'
- BEGIN
- -- Built a sub version, add it to major version
- IF @numberOfDot = 0
- SET @major = @major + @minor * POWER(2, 20) * POWER(2, 20)
- ELSE IF @numberOfDot = 1
- SET @major = @major + @minor * POWER(2, 16) * POWER(2, 16)
- ELSE IF @numberOfDot = 2
- SET @major = @major + @minor * POWER(2, 16)
- ELSE
- -- Extra '.' found, incorrect version format, stop parsing and return 0
- RETURN 0
- SET @minor = 0
- SET @numberOfDot = @numberOfDot + 1
- END
- ELSE
- -- Incorrect version format, stop parsing and return 0
- RETURN 0
- SET @position = @position + 1
- END
- -- Add the last sub version to major
- SET @major = @major + @minor;
- RETURN @major
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement