简体   繁体   English

将nvarchar转换为int时出错

[英]Error converting nvarchar to int

SELECT 
    New_accountid AS AccountId
FROM 
    BingMapsPlatform_MSCRM.dbo.FilteredAccount WITH (NOLOCK)
WHERE 
    new_islicensed = 1
    AND new_accountid NOT IN (SELECT DISTINCT CONVERT(INT,New_AccountId)
                              FROM BingMapsPlatform_MSCRM.dbo.New_keydenylistExtensionBase WITH (NOLOCK)
                              WHERE New_AccountId IS NOT NULL)

I am getting this error from this script. 我从此脚本中收到此错误。 Please help me . 请帮我 。

ErrorMessage : State 1, Line 1 ErrorMessage:状态1,第1行
Conversion failed when converting the nvarchar value 'account 1' to data type int. 将nvarchar值“帐户1”转换为数据类型int时,转换失败。

Is the Id an int?, could be a guid or sequential guid. Id是一个整数吗?可以是GUID或顺序GUID。 If not then divide the table in half, and re run, etc until you determin the row which generates the error (i'd try with just one row to check for sillys first). 如果没有,则将表分成两半,然后重新运行,依此类推,直到您确定产生错误的行为止(我会尝试只用一行来首先检查错误)。 Oh and copy the table contents to a backup first (but you knew that) 哦,先将表内容复制到备份中(但您知道)

This line is causing the error: 此行导致错误:

CONVERT(INT,New_AccountId)

Make a usual select on the table using the filter: where accountId = 'account 1' , change this value and try again. 使用过滤器在表上进行常规选择: where accountId = 'account 1' ,更改此值,然后重试。

Consider using the ISNUMERIC(input) function to determine if its nummeric before converting and if its not then use 0 or -1 as a default value (Take a look at this answer for an example). 考虑使用ISNUMERIC(输入)函数,以确定是否转换之前其nummeric和如果它不再使用0或-1作为默认值(看看这个答案的示例)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM