[英]Conversion Failed Nvarchar to INT
I have two tables called Entry_Data and Data 我有两个表,分别称为Entry_Data和Data
Entry_Data has three columns: Entry_Data具有三列:
EntryID DataID DataTypeID EntryID DataID DataTypeID
1 50 18 1 50 18
2 49 59 2 49 59
30 28 16 30 28 16
Data has two columns: 数据有两列:
DataID Value DataID 值
50 0x00000000033654 50 0x00000000033654
49 Removable 49可移动
28 E:\\Test.txt 28 E:\\ Test.txt
The Value column is an nvarchar field. 值列是一个nvarchar字段。
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: 尝试将所有以0x开头的Value字段转换为int时,我写了一个左联接,以便可以将十六进制值转换为有意义且易于理解的值,但是出现错误:
Conversion failed when converting the nvarchar value '0x00000000033654' to data type int 将nvarchar值'0x00000000033654'转换为数据类型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
In your case expression
, you are returning an nvarchar
for one situation 在您的case expression
,您将为一种情况返回nvarchar
THEN CONVERT(nvarchar, CONVERT(int, Value, 1))
and an integer for the second situation 第二种情况是整数
ELSE DataTypeID
You need to correct your join so it always return and int for the join to work. 您需要更正联接,以便它始终返回并返回int,以使联接起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.