SQL Server中使用表值函数

函数有很多限制,不能使用动态语句,不能使用临时表等等。。。细看一下,直接写语句就行了,不用动态语句

insert into @re select id,parid,@I from videoclasspic where charindex(','+cast(id as varchar(10))+',',','+@parentid+',')>0 and isvalid=1

SqlServer表值函数:

Sql server 的表值函数是返回一个Table类型,table类型相当与一张存储在内存中的一张虚拟表。

实现表值函数很简单:

下面是一个不带输入参数的表值函数

create function tvpoints()

returns  table
as
return
(
select  * from  tb_users
);
这个表值函数数查询所有用户表的数据
对于多语句表值函数,在 BEGIN...END 语句块中定义的函数体包含一系列 Transact-SQL 语句,这些语句可生成行并将其插入将返回的表中。

以下示例创建了一个表值函数.

create  function  tvpoints()
returns  @points table  (x float , y float )
as  begin
insert  @points values (1,2);
insert  @points values (3,4);
return ;
end

 

查询表值函数跟查询普通表一样
select * from tvpoints()
返回的是一张表

带输入参数的表值函数

create  function  tvpoints2(@x AS  int ,@y as  int )
returns  @points table  (x float , y float )
as  begin
insert  @points values (@x,@y);
return ;
end

转载于:https://www.cnblogs.com/shuibi/p/6559215.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值