加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

SQLServer 表值函数与标量值函数 定义方式与调用区别

发布时间:2020-12-12 15:29:36 所属栏目:MsSql教程 来源:网络整理
导读:? 标量值函数创建: Create Function [dbo].[GoosWidth](@GoodsCode varchar(20)) Returns float Begin ???????Declare @Value float ???????Select @Value = GoodsWidth From Master_Goods Where GoodsCode = @GoodsCode ???????Return(@Value) End ? 表值函
?

标量值函数创建:

Create Function [dbo].[GoosWidth](@GoodsCode varchar(20))
Returns float
Begin
???????Declare @Value float
???????Select @Value = GoodsWidth From Master_Goods Where GoodsCode = @GoodsCode
???????Return(@Value)
End

?

表值函数创建:

Create Function [dbo].[GetAllGoods]()
Returns Table
As
?Return(Select * From [Master_Goods])

?

创建一个自定义样式的标量函数

Create Function [dbo].[GetMyStyleDate](@Date DateTime)
Returns nvarchar(20)
Begin
???????Declare @ReturnValue nvarchar(20)
???????Set @ReturnValue = '今天是' + convert(nvarchar(4),datepart(year,@Date)) + '年'
?????????????????????????????????????????????????+ convert(nvarchar(2),datepart(month,@Date)) + '月'
?????????????????????????????????????????????????+ convert(nvarchar(2),datepart(day,@Date)) + '日'
???????return @ReturnValue
End

?

其中标量值函数调用的时候方式如下:Select dbo.GoosWidth('0003')??? 注意:函数前边一定要加上所有者:dbo

表值函数调用方法如下:Select * From GetAllGoods()???????表值函数调用的时候不用加入。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读