在下面的代碼中,我將多個值用逗號分隔到@i_CustomerGroupID和一個值到@ i_LocationID。其中我面臨的問題是「子查詢返回的值超過1 。當子查詢遵循=,!=,<,< =,>,> =或當子查詢用作表達式時,這是不允許的。 聲明已被終止。「。請幫我解決問題。Sql插入錯誤 - 「子查詢返回超過1個值」
ALTER PROCEDURE [dbo].[spInsertCustomerGroupLocationMap]
-- Add the parameters for the stored procedure here
@i_LocationID int,
@i_CustomerGroupID varchar(100)
--WITH ENCRYPTION
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
IF NOT EXISTS (SELECT 1 FROM CustomerGroupLocationMap WHERE LocationID = @i_LocationID AND CustomerGroupID = @i_CustomerGroupID)
BEGIN
INSERT INTO CustomerGroupLocationMap (LocationID, CustomerGroupID) VALUES (@i_LocationID, (SELECT * FROM dbo.CSVToTable(@i_CustomerGroupID)));
END
END