Thng tin: Chuy?n d? li?u nh? phn sang h? th?p l?c phn chu?i

D?ch tiu ? D?ch tiu ?
ID c?a bi: 104829 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

TM T?T

SQL Server khng c built-in Transact-SQL l?nh ? chuy?n ?i d? li?u nh? phn ? m?t chu?i h? th?p l?c phn.

THNG TIN THM

Transact-SQL chuy?n ?i l?nh chuy?n ?i d? li?u nh? phn ? d? li?u nhn v?t trong m?t m?t byte ? th?i trang m?t k? t?. SQL Server m?t m?i byte c?a ngu?n d? li?u nh? phn, chuy?n n ?n m?t gi tr? s? nguyn, sau s? d?ng m gi tr? nguyn nh gi tr? ASCII cho d? li?u i?m ?n nhn v?t. Hnh vi ny p d?ng cho nh? phn, varbinary v d?u th?i gian datatypes.

V d?, dng cc gi tr? nh? phn 00001111 (0x0F trong h? th?p l?c phn) ?c chuy?n ?i chuy?n thnh s? nguyn equivalent l 15, sau thnh nhn v?t m tng ?ng v?i gi tr? ASCII 15, m l khng ?c ?c.

Th? t?c ?c lu tr? sau y c th? ?c s? d?ng ? tr? v? m?t chu?i k? t? m ch?a h? th?p l?c phn ?i di?n c?a m?t gi tr? nh? phn:
   create procedure sp_hexadecimal
     @binvalue varbinary(255)
   as
   declare @charvalue varchar(255)
   declare @i int
   declare @length int
   declare @hexstring char(16)

   select @charvalue = '0x'
   select @i = 1
   select @length = datalength(@binvalue)
   select @hexstring = "0123456789abcdef"

   while (@i <= @length)
   begin

     declare @tempint int
     declare @firstint int
     declare @secondint int

     select @tempint = convert(int, substring(@binvalue,@i,1))
     select @firstint = floor(@tempint/16)
     select @secondint = @tempint - (@firstint*16)

     select @charvalue = @charvalue +
       substring(@hexstring, @firstint+1, 1) +
       substring(@hexstring, @secondint+1, 1)

     select @i = @i + 1

   end

   select 'sp_hexadecimal'=@charvalue
				

V d?, khi th?c thi l?nh sau y ?c th?c hi?n v?i ISQL:
     declare @bin varbinary(255)
     select @bin = @@dbts
     execute sp_hexadecimal @bin
     select 'isql' = @bin
     go
				

n c tr? l?i s?n l?ng tng t? nh sau:
     sp_hexadecimal
     ------------------------------------------------------------------
     0x01000000a60b0000

     (1 row affected)


     isql
     ------------------------------------------------------------------
     0x01000000a60b0000
     (1 row affected)
				

Thu?c tnh

ID c?a bi: 104829 - L?n xem xt sau cng: 17 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft SQL Server 4.21a Standard Edition
  • Microsoft SQL Server 6.0 Standard Edition
  • Microsoft SQL Server 6.5 Standard Edition
  • Microsoft SQL Server 7.0 Standard Edition
T? kha:
kbinfo kbother kbmt KB104829 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:104829

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com