I am trying to update data in a Contacts_CSTM table based on data in a Project_CSTM table. This is the query I’m using, but I get an error: “Conversion failed when converting from a character string to uniqueidentifier”
ALTER PROCEDURE Insurance_Check_Expiration
@ID_C AS NVARCHAR (55) = ID_C
AS
BEGIN
SET NOCOUNT ON
IF EXISTS(SELECT * FROM CONTACTS_CSTM WHERE ID_C = @ID_c)
Update contacts_cstm set insurance_expired_label_c = 'INSURANCE EXPIRED'
WHERE DRIVERS_LICENSE_NUMBER_C IS NOT NULL AND @ID_C=
(SELECT cc.id_c
FROM PROJECT_CSTM PC
JOIN PROJECT P
ON P.ID = PC.ID_C
JOIN PROJECT_RELATION PR
ON PR.PROJECT_ID = P.ID
JOIN CONTACTS C
ON C.ID = PR.RELATION_ID
JOIN CONTACTS_CSTM CC
ON CC.ID_C = C.ID
WHERE CC.ID_C = @ID_C AND INSURANCE_EXPIRED_C ='1')
Thanks.
For one, you’re setting the value of @ID_C to a value (ID_C) which is obviously not a valid GUID.
This is the functional equivalent of what you did, run it and you’ll get the same error.
EDIT: Here’s a functional example based on the OP’s comments: