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 2005 Forums
 Transact-SQL (2005)
 convert varchar to hexString

Author  Topic 

Zath
Constraint Violating Yak Guru

298 Posts

Posted - 2007-07-23 : 14:35:49
I have a field that is binary(6)

A mac address is stored there but first it is converted to
a hex string (binary 6).

In another SP, I need reach a varchar @macAddress
and convert that to the hexString - or binary6.

So,This varChar - 00:60:73:E2:D0:B3
Should be able to convert and compare the value in the binary(6) field.

This line is NOT working....

WHERE (@macAddress IS NULL OR (
ISNULL(DeviceInterface.MAC,CONVERT(binary(6),'00:00:00:00:00:00')) = CONVERT(binary(6), @macAddress)))


Thanks,

Zath

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-23 : 16:45:06
[code]DECLARE @bin BINARY(6),
@vc VARCHAR(17)

SELECT @bin = 0x006073E2D0B3,
@vc = '00:60:73:E2:D0:B3'

SELECT @bin,
@vc,
CASE
WHEN sys.fn_varbintohexstr(@bin) = '0x' + REPLACE(@vc, ':', '') THEN 1
ELSE 0
END AS Match[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -