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');
答案 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
变量