扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:邀月 来源:CSDN 2008年3月28日
关键字: 自定义 Table SQL 数据库 SQL Server
SQL中Table型数据与用户自定义函数(downmoon)
SQL Server 2000 新增了Table型数据:Table型数据不能用来定义列的类型,只能用作T-SQL变量或者作为自定义函数的返回值,下例是一个简单的table 型数据的例子:
Declare @TableVar Table
(Cola int Primary Key,Colb char(3))
Insert Into @TableVar Values (1, 'abc')
Insert Into @TableVar Values (2, 'def')
Select * From @TableVar
Create Function CubicVolume
(@CubeLength decimal(4,1),@CubeWidth decimal(4,1),@CubeHeight decimal(4,1) )
Returns decimal(12,3)
As
Begin
Return (@CubeLength * @CubeWidth * @CubeHeight)
End
--SELECT AppDta.dbo.CubicVolume (10,8,6)
Use pubs
Create Function SalesByStore(@storeid varchar(30))
Returns Table
As
Return (Select title, qty From sales s, titles t
Where s.stor_id = @storeid and t.title_id = s.title_id)
-- select * from sales
SELECT * FROM Pubs.dbo.SalesByStore(7131)如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。