Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.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 2008 如何声明和初始化用户定义的表类型?_Sql Server 2008 - Fatal编程技术网

Sql server 2008 如何声明和初始化用户定义的表类型?

Sql server 2008 如何声明和初始化用户定义的表类型?,sql-server-2008,Sql Server 2008,我创建了这个用户表类型 CREATE TYPE [dbo].[IntArray] AS TABLE ( IntValue INT ) 我还创建了一个函数 CREATE FUNCTION [dbo].[fnProcessIntArray] ( @IntArray as dbo.intArray READONLY ) RETURNS NVARCHAR(max) AS BEGIN -- Input is table of int values -- Output example :

我创建了这个用户表类型

CREATE TYPE [dbo].[IntArray] AS TABLE
(
    IntValue INT
)
我还创建了一个函数

CREATE FUNCTION [dbo].[fnProcessIntArray]
(
    @IntArray as dbo.intArray READONLY
)
RETURNS NVARCHAR(max)
AS
BEGIN
-- Input is table of int values
-- Output example : '1,2,3,4'
...
END
现在我需要测试一个函数,但我不知道怎么做,我试过了

SELECT dbo.fnProcessIntArray((SELECT 1))
-- Error: Operand type clash: int is incompatible with IntArray

SELECT dbo.fnProcessIntArray((SELECT 1,2,3,4))
-- Error: Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

如何将@intArray声明为dbo.intArray?

声明@x dbo.intArray;插入@x值(1)、(2)、(3)、(4);选择dbo.fnProcessIntArray(@x)请将此作为答案发布,供大家查看。