38.数字转换成16进制

153 阅读1分钟
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_int2hex]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[f_int2hex]
GO

/*--数字转换成16进制
*/

/*--调用示例

	--调用
	select dbo.f_int2hex(123)
--*/
create function f_int2hex(@num int)
returns varchar(100)
as
begin
	declare @re varchar(100)
	set @re=''
	while @num>0
		select @re=substring('0123456789ABCDEF',@num%16+1,1)+@re
			,@num=@num/16
	return(@re)
end
go