我收到一个错误,因为SELECT / CASE返回多行,我想。我想请求帮助,并学习如何将我的存储过程从基于单行的参数转换为无参数代码,并能够为多个记录运行存储过程。
整条信息显示:
子查询返回的值超过1。当子查询遵循=,!=,<,< =,>,> =或子查询用作表达式时,不允许这样做。
这是我的代码:
BEGIN
SET NOCOUNT ON;
DECLARE @Desc NVARCHAR(MAX);
SET @DESC = 'Beginning of description ';
SET @Desc = @DESC+(
SELECT
CASE
WHEN LEFT([pd].[Title], 1) = '"'
THEN CONCAT('"', REPLACE([pd].[Title], '"', ''), '"')
END
FROM [dbo].[Data_Feed] [df]
INNER JOIN [dbo].[ProductData] [pd]
ON [df].[sku] = [pd].[ProductID]
WHERE pd.ProductType IN (19, 20, 23, 26, 27));
SET @DESC = (
SELECT
CASE
WHEN [df].[show] IS NOT NULL
THEN CONCAT(@DESC, ' from ', [df].[show])
ELSE CASE
WHEN [df].[primary_performer] IS NOT NULL
THEN CONCAT([df].[primary_performer], ' ', @DESC)
ELSE CASE
WHEN [df].[performer] IS NOT NULL
THEN CASE
WHEN LEN([df].[performer])-LEN(REPLACE([df].[performer], ';', '')) > 1
THEN CONCAT(@DESC, ' by ', REPLACE(STUFF([df].[performer], LEN([df].[performer])-CHARINDEX(';',REVERSE([df].[performer]))+1, 1, ' and '), ';', ', '))
ELSE CONCAT(@DESC, ' by ', REPLACE([df].[performer],';', ' and '))
END
ELSE CASE
WHEN [df].[composer] IS NOT NULL
THEN CASE
WHEN LEN([df].[composer])-LEN(REPLACE([df].[composer], ';', '')) > 1
THEN CONCAT(@DESC, ' by ', REPLACE(STUFF([df].[composer], LEN([df].[composer])-CHARINDEX(';', REVERSE([df].[composer]))+1, 1, ' and '),';', ', '))
ELSE CONCAT(@DESC, ' by ', REPLACE([df].[composer], ';', ' and '))
END
END
END
END
END
FROM [Data_Feed] [df]);
SET @DESC = @DESC+(
SELECT
CASE
WHEN [df].[scoring] IS NULL
THEN CONCAT(RTRIM(@DESC), '.')
ELSE CASE
WHEN CHARINDEX(';', [df].[scoring]) > 0
THEN CONCAT(' in ', LEFT([df].[scoring], CHARINDEX(';', [df].[scoring], 1)-1), ' format.')
ELSE CONCAT(' in ', [df].[scoring], ' format.')
END
END
FROM [Data_Feed] [df]);
UPDATE [Data_Feed]
SET
[description] = @Desc
END;