我在使用select語句在CASE語句中設置返回值時遇到問題......有人可以請看看嗎?SQL案例 - 使用SELECT
DECLARE @SystemTypeId int
SELECT @SystemTypeId = [SystemTypeId] FROM [Properties] WHERE [Id] = @PropertyId
SET @RETURN_VAL =
CASE @SystemTypeId
WHEN 2 THEN (SELECT [Created] FROM [Assets] WHERE [Id] = @AssetId)
WHEN 3 THEN (SELECT dbo.GetAssetValueById([CreatedBy])
FROM [Assets]
WHERE [Id] = @AssetId)
WHEN 9 THEN (SELECT [LastModified]
FROM [Assets]
WHERE [Id] = @AssetId)
ELSE NULL
END
第一步將宣佈**'@ AssetID' ** – JNK
@AssetId已經進一步聲明瞭上面。 –
似乎不管@SystemTypeId是什麼,情況2總是被選中。 –