将Table作为参数传递给函数 [英] Pass Table as a parameter to a function

查看:143
本文介绍了将Table作为参数传递给函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,

是否可以将表作为参数传递给函数。


函数声明会看起来像这样。 ...

ALTER FUNCTION TempFunction(@TempTable TABLE,@ nndd INT)

我的问题是:我必须访问在SP中创建的临时表
a功能

更改程序MySP

BEGIN

....

DECLARE @TmpTable TABLE (...)

....

TempFunction(@TmpTable)

....

结束

谢谢

ArunDhaJ

解决方案

ArunDhaJ(ar *** ***@gmail.com)写道:


是否可以将表作为参数传递给函数。



应该是SQL 2008,目前处于测试阶段。功能

在当前的CTP中可用,但是我还没有玩过它,所以我不能确定它是否适用于函数。 />


我的问题是:我必须访问在SP中创建的临时表

a函数


ALTER程序MySP

BEGIN

....

DECLARE @TmpTable TABLE(...)

....

TempFunction(@TmpTable)

....

END



您可能需要将该函数重写为过程。请参阅此处获取

在当前SQL版本的存储过程之间传递数据的一些提示。
http://www.sommarskog.se/share_data.html

-

Erland Sommarskog, SQL Server MVP, es****@sommarskog.se


联机丛书SQL Server 2005
http: //www.microsoft.com/technet/pro...ads/books.mspx

SQL Server 2000联机丛书
http://www.microsoft.com/sql/prodinf...ons/books.mspx


你走了,这不是一厢情愿的想法 - :)

http://beyondsql.blogspot.com/2007/0...parameter.html

www.beyondsql.blogspot.com




如前所述,程序可行。我们有一个程序来从表中删除所有默认约束。
我将

表的列表传递给此过程(通过调用函数将表的列表加载到表中

变量)。如果您需要进一步的帮助,请重新发布

,我希望能给您一个例子!


Paul


Hi Friends,
Is it possible to pass a table as a parameter to a funtion.

whos function declaration would look some thing like this....
ALTER FUNCTION TempFunction (@TempTable TABLE, @nPId INT)
my problem is: i have to access a temporary table created in an SP in
a function
ALTER PROCEDURE MySP
BEGIN
....
DECLARE @TmpTable TABLE(...)
....
TempFunction(@TmpTable)
....
END
Thanks
ArunDhaJ

解决方案

ArunDhaJ (ar******@gmail.com) writes:

Is it possible to pass a table as a parameter to a funtion.

It should be in SQL 2008, which currently is in beta. The functionality
is available in the current CTP, but I have not played with it, so I
can''t say for sure that it works with functions.

my problem is: i have to access a temporary table created in an SP in
a function
ALTER PROCEDURE MySP
BEGIN
....
DECLARE @TmpTable TABLE(...)
....
TempFunction(@TmpTable)
....
END

You probably need to rewrite the function as a procedure. See here for
some tips of passing data between stored procedures in current SQL versions.
http://www.sommarskog.se/share_data.html

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Here you go and it''s not wishful thinking -:)

http://beyondsql.blogspot.com/2007/0...parameter.html

www.beyondsql.blogspot.com



As already suggested a procedure will work. We have a procedure to
drop all default constraints from our tables. I pass in a list of
tables to this procedure (the list of tables are loaded in to a table
variable by calling a function). If you need further help then re-post
and I can hopefully give you an example!

Paul


这篇关于将Table作为参数传递给函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆