日期:2014-05-18 浏览次数:20628 次
create Function [dbo].[IntToHex](@IntNum int) returns varchar(16) as begin declare @Mods int,@res varchar(16) set @res='' while @IntNum <> 0 begin set @Mods =@IntNum % 16 if @Mods > 9 set @res = Char(Ascii('A')+@Mods-10)+@res else set @res = Cast(@Mods as varchar(4)) + @res set @IntNum = @IntNum/16 end return @res end
------解决方案--------------------
create Function [dbo].[IntToHex](@IntNum int) returns varchar(16) as begin declare @Mods int,@res varchar(16) set @res='' while @IntNum <> 0 begin set @Mods =@IntNum % 16 if @Mods > 9 set @res = Char(Ascii('A')+@Mods-10)+@res else set @res = Cast(@Mods as varchar(4)) + @res set @IntNum = @IntNum/16 end return @res end go declare @lac table (lac_hex varchar(2)) insert into @lac select 'A' union all select 'AB' union all select '2B' declare @lac_in table (lac int) insert into @lac_in select 171 union all select 10 union all select 67 select * from @lac a full join @lac_in b on dbo.[IntToHex](b.lac)=a.lac_hex /* lac_hex lac ------- ----------- AB 171 A 10 NULL 67 2B NULL (4 row(s) affected) */