"=" 和 "like"

declare @v1 varchar(2),@v2 varchar(2)
declare @v3 char(2),@v4 char(2)
select @v1='1',@v2='1 ',@v3='1',@v4='1 '
select datalength(@v1)Lenth_of_v1,datalength(@v2)Lenth_of_v2,datalength(@v3)Lenth_of_v3,datalength(@v4)Lenth_of_v4
select case when @v1=@v2 then '@v1=@v2' else '@v1<>@v2' end as Comp_v1_v2 ,
case when @v3=@v4 then '@v3=@v4' else '@v3<>@v4' end as Comp_v3_v4
select case when @v1 like @v2 then '@v1 like @v2' else '@v1 not like @v2' end as v1_Like_v2 ,
case when @v3 like @v4 then '@v3 like @v4' else '@v3 not like @v4' end as v3_Like_v4

1.为什么@v1=@v2 ?
2.为什么@v1 not like @v2 ?

---------------------------------------------------------------

这个测试很有意思!

declare @v1 varchar(2),@v2 varchar(2)
declare @v3 char(2),@v4 char(2)
select @v1='1',@v2='1 ',@v3='1',@v4='1 '
select datalength(@v1)Lenth_of_v1,datalength(@v2)Lenth_of_v2,datalength(@v3)Lenth_of_v3,datalength(@v4)Lenth_of_v4
select case when @v1=@v2 then '@v1=@v2' else '@v1<>@v2' end as Comp_v1_v2 ,
case when @v3=@v4 then '@v3=@v4' else '@v3<>@v4' end as Comp_v3_v4
select case when @v1 like @v2 then '@v1 like @v2' else '@v1 not like @v2' end as v1_Like_v2 ,
case when @v2 like @v1 then '@v2 like @v1' else '@v2 not like @v1' end as v2_Like_v1 ,
case when @v3 like @v4 then '@v3 like @v4' else '@v3 not like @v4' end as v3_Like_v4

结果:
@v1 not like @v2
@v2 like @v1

---------------------------------------------------------------

等号是忽略空格的
like相反

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus