开发者

UPDATE Select Statement with Multiple Joins

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
 JOI开发者_如何转开发N 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.

CREATE PROCEDURE Insurance_Check_Expiration
  @ID_C AS NVARCHAR (55) = ID_C
  AS
 BEGIN      
 DECLARE @A UNIQUEIDENTIFIER

 SET @A = @ID_C


 END

 exec Insurance_Check_Expiration

EDIT: Here's a functional example based on the OP's comments:

CREATE TABLE GUIDExample (ID_C UNIQUEIDENTIFIER)
GO
CREATE PROC GuidExample_Insert @ID_C UNIQUEIDENTIFIER
AS
BEGIN
    SELECT @ID_C
END
GO
CREATE TRIGGER GUID_Example ON GUIDExample
AFTER INSERT
AS
    DECLARE @ID_C UNIQUEIDENTIFIER

    SELECT @ID_C = ID_C
    FROM Inserted


    EXEC GuidExample_Insert @ID_C
GO

DECLARE @SampleGUID UNIQUEIDENTIFIER

SET @SampleGUID = NEWID()

INSERT GUIDExample (ID_C)
VALUES(@SampleGUID)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜