SQL自定义函数

    技术2022-05-18  16

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

     

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

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

     

    --执行

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

     

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

    use crmdbgocreate function getTable(@DATAID int)returns table --返回表(table)asreturn select * from dbo.DATADICT where DATAID=@DATAID

    --执行

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

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


    最新回复(0)