Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 binary data into sql server 2000

Author  Topic 

chili512
Starting Member

1 Post

Posted - 2006-07-24 : 06:59:42
hi - i am wondering how i can get data in hex format from a remote device via GSM and then process the data into valid values and drop the values into the correct table and fields. this can be done - but i am not sure how. any one any ideas?
cheers jon

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-07-24 : 07:46:13
Here is a function you can use to convert 8-bit (2 char) hex values to SQL TINYINT
CREATE FUNCTION dbo.HexToTINYINT 
(
@Value VARCHAR(2)
)
RETURNS TINYINT
AS
BEGIN
DECLARE @v TINYINT

SELECT @Value = RIGHT(UPPER('00' + @Value), 2)

IF PATINDEX('%[^0-9A-F]%', @Value) < 1
SELECT @v = (CHARINDEX(SUBSTRING(@Value, 2, 1), '0123456789ABCDEF', 1) - 1) +
16 * (CHARINDEX(SUBSTRING(@Value, 1, 1), '0123456789ABCDEF', 1) - 1)

RETURN @v
END

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-07-24 : 08:25:46
You can also convert the data into varchar or varbinary.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -