Declare @CategoryID as int
BEGIN
SELECT
(CASE
WHEN EXISTS(
SELECT t0.Categoryid AS [EMPTY]
FROM Categories AS [t0]
WHERE [t0].Categoryname = @CategoryName
) THEN 1
ELSE 0
END) AS [value]
我希望在exists块内使用t0.Categoryid设置我的变量。如何做到这一点?
我想把then 1替换为类别ID值……
CASE
语句内部使用SET
语句。SET @c = CASE WHEN x THEN y ELSE z END
是有效的,但是CASE WHEN x THEN SET @c = y ELSE SET @c = z END
肯定是无效的。 - MatBailieSELECT @categoryId = (case...)
。 - Joe Taras