gpt4 book ai didi

sql - 无法再次绑定(bind)多部分标识符

转载 作者:行者123 更新时间:2023-12-04 02:49:58 25 4
gpt4 key购买 nike

我正在尝试创建这样的存储过程,

CREATE PROCEDURE [dbo].[SP_Name]
(
@ID varchar(50),
@URL varchar(256)
)
AS
SELECT DISTINCT
Table1.CID, Table2.Name, Table2.aID, Table2.bID,
Table3.SchemeName, Table2.cURL
FROM Table4
INNER JOIN Table5 ON Table5.eID = Table1.eID
INNER JOIN Table2 ON Table2.ID = Table1.CID
INNER JOIN [Table3] ON Table3.aID = Table2.aID AND Table3.bID = Table2.bID
WHERE
Table5.ID = @ID
AND Table2.cURL LIKE '%' + @URL + '%'

但是我收到了这个错误:

Msg 4104, Level 16, State 1, Procedure SP_Name, Line 7
The multi-part identifier "Table1.eID" could not be bound.
Msg 4104, Level 16, State 1, Procedure SP_Name, Line 7
The multi-part identifier "Table1.cID" could not be bound.
Msg 4104, Level 16, State 1, Procedure SP_Name, Line 7
The multi-part identifier "Table1.cID" could not be bound.

即使语法正确。

最佳答案

您必须使用 Table1 添加内部联接

SELECT DISTINCT Table1.CID, 
Table2.Name, Table2.aID, Table2.bID,
Table3.SchemeName, Table2.cURL

FROM Table4
INNER JOIN Table1 ON ....
INNER JOIN Table5 ON Table5.eID = Table1.eID
INNER JOIN Table2 ON Table2.ID = Table1.CID
INNER JOIN [Table3] ON Table3.aID = Table2.aID AND Table3.bID = Table2.bID

WHERE Table5.ID=@ID AND Table2.cURL LIKE '%' + @URL + '%'

或使用 Table1 而不是 Table4

SELECT DISTINCT Table1.CID, 
Table2.Name, Table2.aID, Table2.bID,
Table3.SchemeName, Table2.cURL

FROM Table1
INNER JOIN Table1 ON ....
INNER JOIN Table5 ON Table5.eID = Table1.eID
INNER JOIN Table2 ON Table2.ID = Table1.CID
INNER JOIN [Table3] ON Table3.aID = Table2.aID AND Table3.bID = Table2.bID
WHERE Table5.ID=@ID AND Table2.cURL LIKE '%' + @URL + '%'

关于sql - 无法再次绑定(bind)多部分标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17989401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com