use northwind
go
create function fn_newregion
(@myinput nvarchar(30))
returns nvarchar(30)
begin
if @myinput is null
set @myinput = 'Not Applicable'
return @myinput
end
go
select * from employees
go
insert employees
(lastname,firstname)
values
('David','Hao')
go
select region from employees
go
select dbo.fn_newregion(region) as region from employees
go
--这里必须注明自定义函数的所有者,否则会显示错误
alter function fn_newregion
(@myinput nvarchar(30))
returns nvarchar(30)
begin
if @myinput is null
set @myinput = '涛哥万岁'
return @myinput
end
go
select * from shippers
go
alter function dbo.fu_shippers
(@companyname nvarchar(40))
returns table
as
return
(
select * from shippers
where companyname=@companyname
)
go
select * from dbo.fu_shippers('speedy express')