I have two tables called Entry_Data and Data
Entry_Data has three columns:
EntryID DataID DataTypeID
1 50 18
2 49 59
30 28 16
Data has two columns:
DataID Value
50 0x00000000033654
49 Removable
28 E:\Test.txt
The Value column is an nvarchar field.
I have written a left join while attempting to convert all Value fields that start with 0x to an int so that the Hexadecimal value can be converted into a meaningful and human readable value however I get the error:
Conversion failed when converting the nvarchar value ‘0x00000000033654’ to data type int
SELECT TOP 100
Entry_Data.DataTypeID AS DataTypeID,
CAST(Data.Value AS nvarchar(440)) AS Value,
Data.DataID AS DataID
FROM ActivityLog.Entry_Data
LEFT JOIN ActivityLog.Data
ON ActivityLog.Entry_Data.DataID =
CASE
WHEN DataTypeID = 18 AND
Value LIKE '%0x%' THEN CONVERT(nvarchar, CONVERT(int, Value, 1))
ELSE DataTypeID
END
WHERE DataTypeID = 18