这个守则有什么问题
CREATE FUNCTION [dbo].[ChangeRevision] (@oldRev tinyint) RETURNS varchar(1) AS begin declare @newRev varchar(1) DECLARE @newval int set @newval=CAST (@oldRev as int) case @newval begin when 0 then set @newRev='Z' when 1 then set @newRev='A' when 2 then set @newRev='B' when 3 then set @newRev='C' end return @newRev; END
我有以下错误
关键字“case”附近的语法不正确.
关键字“返回”附近的语法不正确.
解决方法
这应该工作:
SET @newRev = (SELECT case @newval WHEN 0 THEN 'Z' WHEN 1 THEN 'A' WHEN 2 THEN 'B' WHEN 3 THEN 'C' END)