declare @chr varchar(4) = 'yasi'; declare @bin varbinary(4) = convert(varbinary(20), @chr); select @bin bin , CONVERT(varchar(4), @bin, 0) style0 , CONVERT(varchar(4), @bin, 1) style1 , CONVERT(varchar(4), @bin, 2) sytel2 /* bin style0 style1 sytel2 ---------- ------ ------ ------ 0x79617369 yasi 0x79 7961 谿瑚: sys.fn_varbintohexstr */
declare @str_bin varchar(20) set @str_bin = '00E5A473' select convert(binary(4), '0x'+@str_bin, 1) /* 蟆郁骸 0x00E5A473 */