Sql “错误”;从字符串“转换日期和/或时间”时转换失败;显示一个范围而不是另一个范围
在生成月度报告时,每当我更新某个范围的数据时,它都会成功生成,而其他范围的数据则不会 代码1(有效): 但当我查询6月份(第6个月)时,它显示了错误 代码2(不工作)Sql “错误”;从字符串“转换日期和/或时间”时转换失败;显示一个范围而不是另一个范围,sql,sql-server,sql-server-2008,Sql,Sql Server,Sql Server 2008,在生成月度报告时,每当我更新某个范围的数据时,它都会成功生成,而其他范围的数据则不会 代码1(有效): 但当我查询6月份(第6个月)时,它显示了错误 代码2(不工作) 由于您的第一个查询工作正常,我不能抱怨该语句,而应该是数据造成了问题。我建议使用数据类型DATE声明@startdate和@enddate等参数,并将其分配给查询。通过这种方式,我们确保系统使用提供的字符串作为日期 希望这有帮助 始终使用日期时间数据类型和明确的日期时间格式YYYYMMDD格式 update warehouse_t
由于您的第一个查询工作正常,我不能抱怨该语句,而应该是数据造成了问题。我建议使用数据类型DATE声明@startdate和@enddate等参数,并将其分配给查询。通过这种方式,我们确保系统使用提供的字符串作为日期
希望这有帮助 始终使用日期时间数据类型和明确的日期时间格式YYYYMMDD格式
update warehouse_ticket_header
set resolution_time = resolution_time_duplicate
where open_date_time >= '20150301' and open_date_time <='20150601'
and config_item like '%Merlin%'
and resolution_time_duplicate is not null and resolution_time is null
更新仓库\u票据\u标题
设置分辨率时间=分辨率时间重复
如果open_date_time>='20150301'和open_date_time,那么为什么在第一个示例中未观察到此错误
update warehouse_ticket_header
set resolution_time = CONVERT(varchar(17), resolution_time_duplicate, 120)
where
open_date_time between '03/01/2015' and '06/01/2015'
and config_item like '%Merlin%'
and resolution_time_duplicate is not null
and resolution_time is null
update warehouse_ticket_header
set resolution_time = resolution_time_duplicate
where open_date_time >= '20150301' and open_date_time <='20150601'
and config_item like '%Merlin%'
and resolution_time_duplicate is not null and resolution_time is null