Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 如何在SQL Server中按行打印表?_Sql Server_Tsql_Stored Functions - Fatal编程技术网

Sql server 如何在SQL Server中按行打印表?

Sql server 如何在SQL Server中按行打印表?,sql-server,tsql,stored-functions,Sql Server,Tsql,Stored Functions,我创建了一个输出数字表的函数,下面是我的UDF标量函数: create function fntable(@a int) returns varchar(250) as begin declare @b int, @c varchar(250),@e varchar(50)='' set @b=1 while (@b<=10) begin set @c=@a*@b set @e=@e+@c set @b=@b+1 end return @e end 创建函数表(@a int) 返回var

我创建了一个输出数字表的函数,下面是我的UDF标量函数:

create function fntable(@a int)
returns varchar(250)
as begin
declare @b int, @c varchar(250),@e varchar(50)=''
set @b=1
while (@b<=10)
begin
set @c=@a*@b
set @e=@e+@c
set @b=@b+1
end
return @e
end
创建函数表(@a int)
返回varchar(250)
作为开始
声明@b int,@c varchar(250),@e varchar(50)=”
设置@b=1
while(@b您需要一个表值函数。按原样使用您的代码,这大致可以转换为:

create function fntable(@a int)
returns @e table(c int)
as begin
    declare @b int = 1
    while (@b <= 10)
    begin
        insert into @e values (@a * @b)
        set @b += 1
    end

    return
end
改变


是的,我可以,但如果可能的话,我想根据我的代码显示。
create function fntable(@a int)
returns table as
return (
    select @a * 1 as c
    union all
    select @a * 2 as c
    union all
    select @a * 3 as c
    union all
    select @a * 4 as c
    union all
    select @a * 5 as c
    union all
    select @a * 6 as c
    union all
    select @a * 7 as c
    union all
    select @a * 8 as c
    union all
    select @a * 9 as c
    union all
    select @a * 10 as c
)
set @e=@e+@c
set @e=@e+@c + CHAR(10)