zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    poj1703--Find them, Catch them
    poj2828--Buy Tickets
    POJ 2594 Treasure Exploration(Floyd+最小路径覆盖)
    HDU
    二分图的一些性质
    HDU
    POJ 1659 Frogs' Neighborhood (Havel定理构造图)
    HDU
    HDU
    2018 Multi-University Training Contest 1
  • 原文地址:https://www.cnblogs.com/shuibi/p/6559215.html
Copyright © 2011-2022 走看看