基于具有 3 条记录的名为 TableCodes 的其他表
Code
1508
1509
1510
我从我的查询 ia temporal table 中得到了这个结果....
CapacityDate InstallerCode WorkAreadID FoxtelCodeID value
2/8/12 BAW 7 1508 3
3/8/12 BAW 7 1508 1
4/8/12 BAW 7 1509 1
我需要在同一个表中插入基于值 = 0 的 TableCodes 缺失的其他记录
我要这个
CapacityDate InstallerCode WorkAreadID FoxtelCodeID value
2/8/12 BAW 7 1508 3
2/8/12 BAW 7 1509 0
2/8/12 BAW 7 1510 0
3/8/12 BAW 7 1508 1
3/8/12 BAW 7 1509 0
3/8/12 BAW 7 1510 0
4/8/12 BAW 7 1508 1
4/8/12 BAW 7 1509 0
4/8/12 BAW 7 1510 0
我正在使用以下代码
Insert into #TmpAdjustmentTable (
CapacityDate, InstallerID, InstallerCode, InstallerName,
bThisIsAnAdjustment, sStatusOfCapacity, WorkAreadID, WORKAREA,
CapacityState, FoxtelCodeID, SINTERNALLABELFORCAPACITY,
SLABELFORCAPACITY, CapacityUnits, Capacity, MaxJobs, CommentsForDay
)
select
ta.CapacityDate, ta.InstallerID, ta.InstallerCode, ta.InstallerName,
1, ta.sStatusOfCapacity, ta.WorkAreadID, ta.WORKAREA,
ta.CapacityState, FoxtelCodes.SYSID, FoxtelCodes.SINTERNALSHORTLABELFORCAPACITY,
FoxtelCodes.SLABELFORCAPACITY, 0, 0, 0, ta.CommentsForDay
from #TmpAdjustmentTable ta
inner JOIN FoxtelCodes
On FoxtelCodes.SYSID <> ta.FoxtelCodeID
and FoxtelCodes.BCOLLECTTHISFORCAPACITY = 1
但我得到了...
CapacityDate InstallerCode WorkAreadID FoxtelCodeID value
2/8/12 BAW 7 1508 3
2/8/12 BAW 7 1509 0
2/8/12 BAW 7 1510 0
3/8/12 BAW 7 1508 1
3/8/12 BAW 7 1508 0
3/8/12 BAW 7 1509 0
3/8/12 BAW 7 1509 0
3/8/12 BAW 7 1510 0
3/8/12 BAW 7 1510 0
4/8/12 BAW 7 1508 1
4/8/12 BAW 7 1508 0
4/8/12 BAW 7 1509 0
4/8/12 BAW 7 1509 0
4/8/12 BAW 7 1510 0
4/8/12 BAW 7 1510 0