[英]Error converting data type varchar to numeric (Newbie)
I am new to this so be gentle. 我是新手,所以要温柔。 I am running this script to update a column that's blank with a 108. The column is set to numeric(18, 0)
. 我正在运行此脚本以使用108更新一个空白的列。该列设置为numeric(18, 0)
。 why am I getting this message and how can I get past it. 为什么我收到这条消息,我怎么能通过它。
Update HL7ManagerRecords
set ScheduleID = 108
where ScheduleID =''
Could be the fields is null 可能是字段为空
Update HL7ManagerRecords
set ScheduleID = 108
where ScheduleID is null
The column ScheduleID
is set to numeric(18, 0)
but you try to find all records where ScheduleID
equals an empry string: where ScheduleID =''
. 列ScheduleID
设置为numeric(18, 0)
但你试图找到其中的所有记录ScheduleID
等于一个empry字符串: where ScheduleID =''
。
Use IS NULL
instead 请改用IS NULL
Update HL7ManagerRecords
set ScheduleID = 108
where ScheduleID IS NULL
You will need to post the schema for the Table. 您需要发布表的架构。 My assumption is ScheduleID is a numeric. 我的假设是ScheduleID是一个数字。 Since it is a numeric the ScheduleID is not blank, because it holds a number numeric MSDN . 由于它是数字,因此ScheduleID不为空,因为它包含数字MSDN 。 My assumption is it is null
, because that is the default value if you create a numeric
column and do not specify if it is null
or not. 我的假设是它为null
,因为如果您创建一个numeric
列并且不指定它是否为null
那么这是默认值。 So what you will need to do is 所以你需要做的是
Update HL7ManagerRecords
set ScheduleID = 108
where ScheduleID is null
If for some reason down the line you need to take a numeric data type and treat it as a blank string or change it to a string with a specific value, you could use something like ISNULL(ScheduleID,'') = ''. 如果出于某种原因需要采用数字数据类型并将其视为空字符串或将其更改为具有特定值的字符串,则可以使用类似ISNULL(ScheduleID,'')=''的内容。 Like the other guys said, "is null" will work just fine, just another way to do it. 就像其他人说的那样,“is null”会很好用,只是另一种方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.