声明函数时出现大小写错误,现在*中有错误

时间:2017-11-22 08:46:57

标签: sql sql-server-2008

create function whichcountry(@city varchar(20)) returns varchar(30)
as
begin
declare @return varchar(30)
select @return = 
    CASE @city
when 'New delhi' then 'India'
when 'Mumbai' then 'India'
when 'Dhaka' then 'Bangladesh'
else 'UNKNOWN'
end
return @return
end

select country = dbo.whichcountry(city.city),city *from city
create table city(eno int,
                  ename varchar(20),
                  city varchar(30));

insert into city values(1,'Ray','New Delhi'),
                       (2,'Jash','Mumbai'),
                       (3,'Ravi','Dhaka');

1 个答案:

答案 0 :(得分:0)

更正如下(SQL Server)

create function whichcountry(@city varchar(20)) returns varchar(30)
as
begin
declare @return varchar(30)
select @return = 
    CASE @city
when 'New delhi' then 'India'
when 'Mumbai' then 'India'
when 'Dhaka' then 'Bangladesh'
else 'UNKNOWN'
end
return @return
end

更正:

CASE @city值未分配给@return变量