“将 varchar 值 'NULL' 转换为数据类型 int 时转换失败" [英] "Conversion failed when converting the varchar value 'NULL' to data type int"

查看:127
本文介绍了“将 varchar 值 'NULL' 转换为数据类型 int 时转换失败"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我向长表中插入记录时,出现错误将 varchar 值 'NULL' 转换为数据类型 int 时转换失败"如何确定哪些列错误?

When I insert records into a long table,I am getting the error "Conversion failed when converting the varchar value 'NULL' to data type int" How can I determine which column errors out?

该表有很多字段和数百万条记录.当我尝试将NULL"字符串插入某处的整数列时,每次迭代都需要 10 分钟来轰炸.我以为 SQL Server 可以告诉我列的确切名称:(

The table has many fields and millions of records. Each iteration takes 10 minutes to bomb when I try to insert "NULL" string into integer column somewhere. I thought SQL server can tell me exact name of the column :(

推荐答案

如果值确实是NULL,就不会出现转换错误.但是,您有一个字符串 = "NULL",那么您会收到此错误.

If the value is truly NULL, there wouldn't be a conversion error. However, you have a string = "NULL" then you would get this error.

你可以做的是...

NullIf(YourValueHere, 'NULL')

NullIf 如果第一个参数与第二个参数不同,则返回第一个参数的值.如果参数相同,NullIf 将返回NULL.

NullIf returns the value of the first parameter if it is not the same as the second parameter. If the parameters are the same, NullIf will return NULL.

例如:

Select NullIf('Any Value', 'NULL')

Select NullIf('null','null')

第一个将返回'Any Value',第二个将返回NULL(不是'null')

The first will return 'Any Value' and the second will return NULL (not 'null')

这篇关于“将 varchar 值 'NULL' 转换为数据类型 int 时转换失败"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆