具有多个连接的 UPDATE Select 语句
我正在尝试根据 Project_CSTM
表中的数据更新 Contacts_CSTM
表中的数据。这是我正在使用的查询,但出现错误:“从字符串转换为 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')
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
其一,您将 @ID_C 的值设置为一个值 (ID_C),这显然不是有效的 GUID。
这与您所做的功能等效,运行它,您会得到相同的错误。
编辑:这是一个基于OP评论的功能示例:
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: