Home > Database > Mysql Tutorial > body text

sqlserver中软件版本号进行字符串对比比较大小

WBOY
Release: 2016-06-07 17:43:28
Original
2050 people have browsed it

sqlserver中软件版本号进行字符串对比比较大小 sql 中直接对 1.2.1.57 1.2.12.57 这样的版本号进行对比是有问题的 需要进行下转换处理 把1.2.1.57 转换为00001000020000100057来进行比较 [fun_split_version] 用于进行转换的 create function [dbo].[fun_spl

sqlserver中软件版本号进行字符串对比比较大小

sql 中直接对 1.2.1.57  1.2.12.57  这样的版本号进行对比是有问题的

需要进行下转换处理

把1.2.1.57 转换为00001000020000100057来进行比较

[fun_split_version]  用于进行转换的
create function [dbo].[fun_split_version]
(
@version varchar(50)--版本号
)
returns decimal(20, 0)
as
begin
-- select [dbo].[fun_split_version]('12312.23344.34234.53441');
--declare @version varchar(50)
--set @version='12.2344.34234.53441'
declare @return decimal(20, 0)
declare @v_1 varchar(20)
declare @v_2 varchar(20)
declare @v_3 varchar(20)
declare @v_4 varchar(20)
declare @wz1 int,@wz2 int ,@wz3 int,@wz4 int
select @wz1=charindex('.',@version),@wz2=charindex('.',@version,CHARINDEX('.',@version)+1)
,@wz3= charindex('.',@version, charindex('.',@version,CHARINDEX('.',@version)+1)+1)

set @v_1=right('0000'+ substring(@version,0,@wz1),5)
set @v_2=right('0000'+ substring(@version,@wz1+1,@wz2-@wz1-1),5)
set @v_3=right('0000'+ substring(@version,@wz2+1,@wz3-@wz2-1),5)
set @v_4=right('0000'+ substring(@version,@wz3+1,len(@version)-@wz3),5)

-- select @v_1,@v_2,@v_3,@v_4

set @return=convert( decimal(20, 0) ,@v_1+@v_2+@v_3+@v_4)
return @return
end

 

posted on

,虚拟主机,虚拟主机,网站空间
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template