SQL自定义函数

来源:互联网 发布:动漫 惊艳 音乐 知乎 编辑:程序博客网 时间:2024/04/30 15:15

嘿嘿!!!今天又学了一点点东西,是SQL自定义函数哦,给大家分享一下我的成果。

 

--自定义一个函数getValue 参数为@id int类型

create function getValue(@id int)
returns  varchar(20) --返回的数据
as
begin
declare @t varchar(20) --声明变量
set @t=( select  DATNO  from dbo.DATADICT where DATAID=@id ) --赋值
return @t
end

 

--执行

select  dbo.getValue(1); --数据库dbo拥有者

 

--自定义一个函数getValue 参数为@id int类型

use crmdb
go
create function getTable(@DATAID int)
returns table --返回表(table)
as
return select * from dbo.DATADICT where DATAID=@DATAID

--执行

select * from dbo.getTable(1); --数据库dbo拥有者


哈哈,有学得一点知识...........