I am not sure why the below code is giving errors when I try to create a stored procedure. I am relatively inexperienced with 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
The error that I get is:
Line 21 Invalid column name ‘IndividualID’.
If I remove the line of code inserting individualID then it gives the same error about the UniqueColID
This is strange because in that given table there IS a column IndividualID so I don’t know why it won’t recognize it….I typed this code in MS Excel then copy pasted it into notepad, could that be why the code isn’t working?
I copied one row from that table and as you can see it DOES have IndividualID:
IndividualID
059D1263-F0F3-4D19-8C56-0FC7D2B5266E
Double check your table
TableInvolvedPersonand make sure the columnIndividualIDis spelled the same.Updated
When you updated your question, you added a value for
IndividualID. The value you added is a Guid, which can possibly be stored in SQL Server as aUNIQUEIDENTIFIERcolumn. But the type you declared on your stored procedure is aVARCHAR. Can you double check your types? What is the type for IndividualID on both the original table and the table you are copying into? Do they match?