這種情況跟我上一個問題有關,但我已經用了另一種方式,因爲我發現我正在嘗試做的事,我不能在視圖中做,它需要成爲一個功能。創建函數時的錯誤
但是我有連接到該線程的底部的代碼,但我得到這些錯誤:
Msg 4104, Level 16, State 1, Procedure fn_COT_TEST, Line 27 [Batch Start Line 0]
The multi-part identifier "Contact_Group_Contacts_T.Relationship_Code_ID" could not be bound.
Msg 4104, Level 16, State 1, Procedure fn_COT_TEST, Line 27 [Batch Start Line 0]
The multi-part identifier "Contact_Group_Contacts_T.Relationship_Code_ID" could not be bound.
Msg 4104, Level 16, State 1, Procedure fn_COT_TEST, Line 27 [Batch Start Line 0]
The multi-part identifier "Contact_Group_Contacts_T.Relationship_Code_ID" could not be bound.
Msg 4104, Level 16, State 1, Procedure fn_COT_TEST, Line 27 [Batch Start Line 0]
The multi-part identifier "Contact_Group_Contacts_T.Relationship_Code_ID" could not be bound.
Msg 4104, Level 16, State 1, Procedure fn_COT_TEST, Line 27 [Batch Start Line 0]
The multi-part identifier "Contact_Group_Contacts_T.Relationship_Code_ID" could not be bound.
Msg 4104, Level 16, State 1, Procedure fn_COT_TEST, Line 27 [Batch Start Line 0]
The multi-part identifier "Contact_Group_Contacts_T.Relationship_Code_ID" could not be bound.
Msg 4104, Level 16, State 1, Procedure fn_COT_TEST, Line 27 [Batch Start Line 0]
The multi-part identifier "Contact_Group_Contacts_T.Relationship_Code_ID" could not be bound.
Msg 444, Level 16, State 2, Procedure fn_COT_TEST, Line 27 [Batch Start Line 0]
Select statements included within a function cannot return data to a client.
Msg 4104, Level 16, State 1, Procedure fn_COT_TEST, Line 29 [Batch Start Line 0]
The multi-part identifier "Contact_Group_Contacts_T.Main_Group_Contact_BT" could not be bound.
Msg 444, Level 16, State 2, Procedure fn_COT_TEST, Line 29 [Batch Start Line 0]
Select statements included within a function cannot return data to a client.
Msg 455, Level 16, State 2, Procedure fn_COT_TEST, Line 29 [Batch Start Line 0]
The last statement included within a function must be a return statement.
我的代碼如下。我盡我所能,但完全卡住了。我究竟做錯了什麼?
CREATE FUNCTION [dbo].[fn_COT_POA] (@CONTACT_ID INT)
RETURNS VARCHAR
AS
BEGIN
DECLARE @COUNT INT;
SET @COUNT =
(select COUNT(CONTACT_ID)
from Contact_Group_Contacts_T
where CONTACT_ID = @CONTACT_ID)
RETURN @COUNT
IF @COUNT > 1
select @CONTACT_ID where Contact_Group_Contacts_T.Relationship_Code_ID in (2801,2802,2803,2804,2805,2806,2807)
ELSE
select @CONTACT_ID where Contact_Group_Contacts_T.Main_Group_Contact_BT = 1
END
GO
我所要做的僅僅是有這些關係的代碼標識的,如果他們沒有得到這些關係碼的ID,然後選擇具有main_group_contact_bt標誌爲1
聯繫人中選擇聯繫人感謝丹
標籤的DBMS你正在使用。該代碼是特定於產品的。 – jarlh
爲什麼你的功能中間有這條線? 'return @ count'你的函數在返回之後想要停止。 – SqlZim
@SqlZim - 我在網上關注一個示例,可能會給我提示。我不知道我是否應該。無論如何,如果我把它取出不起作用 – dgoodwin