SQLServer 表值函数与标量值函数 定义方式与调用区别
2010-06-18 18:04
375 查看
转自:http://www.52net.org/html/Ado_Net/20090701/4957.html
SQLServer 表值函数与标量值函数 定义方式与调用区别
标量值函数创建:
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() 表值函数调用的时候不用加入。
SQLServer 表值函数与标量值函数 定义方式与调用区别
标量值函数创建:
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() 表值函数调用的时候不用加入。
相关文章推荐
- SQLServer 表值函数与标量值函数 定义方式与调用区别
- SQLServer 表值函数与标量值函数 定义方式与调用区别
- SQLServer 表值函数与标量值函数 定义方式与调用区别
- SQLServer 表值函数与标量值函数 定义方式与调用区别
- SQLServer 表值函数与标量值函数 定义方式与调用区别
- SQL表值函数和标量值函数的区别 推荐
- ES6中箭头函数的定义与调用方式详解
- 函数调用方式的区别[thiscall,__cdecl,__stdcall]
- 浅谈js函数三种定义方式 & 四种调用方式 & 调用顺序
- 云星数据---Scala实战系列(精品版)】:Scala入门教程014-Scala实战源码-Scala函数定义与调用方式
- _stdcall与_cdecl的区别(函数调用方式)
- 函数调用方式--__thiscall调用方式和__cdecl,__stdcall有什么区别
- 函数调用方式的区别[thiscall,__cdecl,__stdcall]
- 函数调用方式的区别[thiscall,__cdecl,__stdcall]
- 函数调用方式的区别
- 函数调用方式--__thiscall调用方式和__cdecl,__stdcall有什么区别
- 函数调用方式--__thiscall调用方式和__cdecl,__stdcall有什么区别
- 【转】函数调用方式的区别[thiscall,__cdecl,__stdcall]
- JS函数定义方式的区别介绍
- __cdecl、_stdcall 、_fastcall、_thiscall 函数调用方式与区别