我已多次更改此查询但仍看到'0行受影响。一切都在SELECT
语句中有效,但在UPDATE
中失败。
以下是查询:
UPDATE tblVisitLog
SET tblVisitLog.TimeOUT = (SELECT CAST(SUBSTRING(tblScheduleData.E_Time, 1,2 ) + ':' + SUBSTRING(tblScheduleData.E_Time, 3,2) + ':00.000' AS datetime)
FROM tblScheduleData
WHERE tblVisitLog.Encounter_code = tblScheduleData.Encounter_code),
tblVisitLog.Provider = (SELECT Provider
FROM tblScheduleData s
WHERE tblVisitLog.Encounter_code = s.Encounter_code),
tblVisitLog.recStatus = 0,
tblVisitLog.Printed = N'N'
WHERE
tblVisitLog.TimeOUT IS NULL
AND tblVisitLog.Provider IS NULL
数据类型为:
Encounter_code (int, null)
TimeOUT (datetime, null)
Provider (nvarchar(50), null)
recStatus (smallint, not null)
Printed (nvarchar(50), null)
我正在更新的值都是NULL,我从tblScheduleData.E_Time
拉出的值为varchar(4), null
,格式为'1045'。
答案 0 :(得分:1)
您的更新声明将使用此处的联接更清洁。这样的事情。
UPDATE vl
SET TimeOUT = CAST(SUBSTRING(s.E_Time, 1,2 )+ ':' + SUBSTRING(s.E_Time, 3,2) + ':00.000' AS datetime)
, Provider = s.Provider
, recStatus = 0
, Printed = N'N'
from tblVisitLog vl
join tblScheduleData s on vl.Encounter_code = s.Encounter_code
WHERE vl.TimeOUT Is NULL
AND vl.Provider Is Null
答案 1 :(得分:0)
信息非常明确'0 rows affected'
因此,尝试执行此查询,您将看到一个空结果
select * from tblVisitLog
WHERE TimeOUT Is NULL AND Provider Is Null
首先更改标准