我不确定为什么在我尝试创建存储过程时下面的代码会出错。我对SP相对缺乏经验。
CREATE PROCEDURE [dbo].[InsertDuplicateFields]
(@UniqueColID varchar(50), @IndividualID varchar(50) = null)
AS
Begin
INSERT INTO TableCollisionBegin
SELECT * FROM TableCollisionBegin
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableCollisionDetails
SELECT * FROM TableCollisionDetails
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableCollisionLocation
SELECT * FROM TableCollisionLocation
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableDriver
SELECT * FROM TableDriver
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableFollowUp
SELECT * FROM TableFollowUp
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableOfficerLogs
SELECT * FROM TableOfficerLogs
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TablePolice
SELECT * FROM TablePolice
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableRecVerified
SELECT * FROM TableRecVerified
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableSignature
SELECT * FROM TableSignature
WHERE [IndividualID] = @IndividualID;
INSERT INTO TableTrailer
SELECT * FROM TableTrailer
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableValidateLog
SELECT * FROM TableValidateLog
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableVehicle
SELECT * FROM TableVehicle
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableWitness
SELECT * FROM TableWitness
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableInvolvedPerson
SELECT * FROM TableInvolvedPerson
WHERE [IndividualID] = @IndividualID;
INSERT INTO TableStatement
SELECT * FROM TableStatement
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableCollisionDiagram
SELECT * FROM TableCollisionDiagram
WHERE [UniqueColID] = @UniqueColID;
END
我得到的错误是:
第 21 行无效的列名“IndividualID”。
如果我删除插入的代码行,individualID
那么它会给出关于UniqueColID
这很奇怪,因为在给定的表中有一个列IndividualID
,所以我不知道为什么它无法识别它....我在 MS Excel 中输入了这段代码,然后将其复制粘贴到记事本中,这可能是代码不正确的原因吗?不工作?
我从该表中复制了一行,如您所见,它确实有IndividualID
:
IndividualID
059D1263-F0F3-4D19-8C56-0FC7D2B5266E