2

我有一个过程和一些自定义类型来传递一些数据给它:

CREATE TYPE StringList AS TABLE
(Value NVARCHAR(255));

GO

CREATE TYPE KeyValueList AS TABLE
(
Id uniqueidentifier,
Value NVARCHAR(255));

GO

CREATE PROCEDURE 
#update_AttributeFormel(
    @modelPrefix NVARCHAR(255), 
    @definitionNeutralName NVARCHAR(255), 
    @newFormula NVARCHAR(255),
    @providersToRemove StringList READONLY,
    @providersToAdd KeyValueList READONLY)
    AS  ....

ManagementStudio 没有显示任何错误(就像我注释掉类型声明时一样),但是当我执行脚本时,我收到以下错误:

Msg 2715, Level 16, State 3, Procedure #update_AttributeFormel, Line 2
Column, parameter, or variable #4: Cannot find data type StringList.
Parameter or variable '@providersToRemove' has an invalid data type.
Msg 2715, Level 16, State 3, Procedure #update_AttributeFormel, Line 2
Column, parameter, or variable #5: Cannot find data type KeyValueList.
Parameter or variable '@providersToAdd' has an invalid data type.

此处解释的实现:

  1. http://www.simple-talk.com/sql/t-sql-programming/temporary-tables-in-sql-server/

  2. http://www.sqlteam.com/article/sql-server-2008-table-valued-parameters

有谁知道为什么会这样?

4

2 回答 2

3

我很确定这是由于在 tempdb 空间中使用CREATE PROCEDURE 创建#update_AttributeFormel了过程。请参阅此SQL Fiddle,当类型和过程位于同一数据库中时,它可以完美运行。

代码复制如下:

CREATE TYPE StringList AS TABLE
(Value NVARCHAR(255));
GO

CREATE TYPE KeyValueList AS TABLE
(
Id uniqueidentifier,
Value NVARCHAR(255));
GO

CREATE PROCEDURE update_AttributeFormel(
    @modelPrefix NVARCHAR(255), 
    @definitionNeutralName NVARCHAR(255), 
    @newFormula NVARCHAR(255),
    @providersToRemove StringList READONLY,
    @providersToAdd KeyValueList READONLY)
AS
SELECT * FROM @providersToRemove
GO

declare @SL StringList;
insert @SL select 'abcdef' union all select 'ok';
declare @KVL KeyValueList;

exec update_AttributeFormel null,null,null,@SL,@KVL;
于 2012-10-02T07:29:48.610 回答
-1

您必须在 tempdb 中创建自定义数据类型,才能在不同的数据库中识别它。

于 2014-10-29T18:23:11.400 回答