本文介绍了在表值函数中声明变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在表值函数中声明变量?
解决方案
有两种风格的表值函数。一个只是一个select语句,一个可以有更多的行,而不仅仅是一个select语句。
这不能有一个变量:
create function Func()返回表
作为
返回
选择10作为ColName
<$ c $ c> create function Func()
返回@T table(ColName int)
as
begin
declare @Var int
set @Var = 10
插入@T(ColName)值(@Var)
返回
结束
How can I declare a variable in a table valued function?
解决方案There are two flavors of table valued functions. One that is just a select statement and one that can have more rows than just a select statement.
This can not have a variable:
create function Func() returns table as return select 10 as ColName
You have to do like this instead:
create function Func() returns @T table(ColName int) as begin declare @Var int set @Var = 10 insert into @T(ColName) values (@Var) return end
这篇关于在表值函数中声明变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!