简体   繁体   English

将用户定义的表类型与生成的数据库部署脚本一起使用时出现问题

[英]Problem using user-defined table type with generated database deployment script

I'm having a strange issue with VS2010's database project not able to execute a generated deployment script that uses a user-defined table type in an SP's parameter list. 我在VS2010的数据库项目中遇到一个奇怪的问题,该项目无法执行在SP的参数列表中使用用户定义的表类型的生成的部署脚本。 I get the following error when executing the deployment script: 执行部署脚本时出现以下错误:

Error SQL01268: .Net SqlClient Data Provider: Msg 137, Level 16, State 1, Procedure AppSearch, Line 36 Must declare the scalar variable "@platforms". 错误SQL01268:.Net SqlClient数据提供程序:消息137,级别16,状态1,过程AppSearch,第36行必须声明标量变量“ @platforms”。

The @platforms variable here is a user-defined table type, that is defined simply like this: @platforms变量是用户定义的表类型,其定义如下:

CREATE TYPE [dbo].[IdList] AS TABLE 
(
    Id      uniqueidentifier
);

The stored procedure that I am creating looks like the following, which uses the UDDT as one of its parameters: 我正在创建的存储过程如下所示,它使用UDDT作为其参数之一:

PRINT N'Creating [dbo].[AppSearch]...';


GO
CREATE PROCEDURE [dbo].[AppSearch]
    @nameContains           nvarchar(30),
    @descriptionContains    nvarchar(max),
    @isEditorsPick          bit,
    @dateAddedStart         datetime,
    @dateAddedEnd           datetime,
    @platforms              IdList      readonly
AS
begin
    select
        l.Id as [LibraryId],
        l.Name as [LibraryName],
        l.Description as [LibraryDescription],
        c.Id as [CategoryId],
        c.Name as [CategoryName],
        c.Description as [CategoryDescription],
        a.Id as [AppId],
        a.Name as [AppName],
        a.Description as [AppDescription],
        a.IsEditorsPick as [AppIsEditorsPick],
        a.DateAdded as [AppDateAdded],
        p.Id as [PlatformId],
        p.Name as [PlatformName],
        p.Architecture as [PlatformArchitecture]
    from
        Library l
        inner join Category c               on l.Id = c.ParentLibraryId
        inner join App a                    on c.Id = a.ParentCategoryId
        inner join AppSupportedPlatform px  on a.Id = px.AppId
        inner join Platform p               on px.PlatformId = p.Id
    where
            (@nameContains is not null and a.Name like '%' + @nameContains + '%')
        and (@descriptionContains is not null and a.Description like '%' + @descriptionContains + '%')
        and (@isEditorsPick is not null and a.IsEditorsPick = @isEditorsPick)
        and (@dateAddedStart is not null and @dateAddedEnd is not null and a.DateAdded between @dateAddedStart and @dateAddedEnd)
        and (@platforms is not null and p.Id in (select Id from @platforms))
end
GO

The deployment script gets executed using SQLCMD mode. 使用SQLCMD模式执行部署脚本。 Any ideas on why I'm getting the above error? 关于为什么会出现上述错误的任何想法?

Thanks in advance! 提前致谢!

Consider that a table type should act somewhat like a table. 考虑一个表类型应该有点像一个表。 You can't say "if TABLE is NOT NULL" so why should you be able to say "if TABLE TYPE is NOT NULL"? 您不能说“如果TABLE NOT NOT NULL”,那么为什么要说“如果TABLE TYPE NOT NOT NULL”呢? I haven't used TVPs extensively, but how about checking that the TVP is not empty: 我没有广泛使用TVP,但是如何检查TVP是否为空:

AND (EXISTS (SELECT 1 FROM @platforms) AND p.Id IN (SELECT Id FROM @platforms));

The latter might be enough (again that is more from lack of playing with TVPs than anything) or maybe: 后者可能就足够了(再次,这主要是由于缺乏与TVP一起玩比什么都没有),或者也许是:

AND (p.Id IN (SELECT Id FROM @platforms) OR NOT EXISTS (SELECT 1 FROM @platforms));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SMO无法执行具有用户定义表类型的脚本 - SMO fails to execute script with user-defined table type 在SQL Server数据库之间传递用户定义的表类型 - Passing a user-defined table type between SQL Server database 使用用户定义的表类型在SQL中插入和更新 - Insert and Update in SQL Using User-Defined Table Type 无法修改用户定义的表类型 - Unable to Modify User-Defined Table Type 使用用户定义的函数搜索表 - Searching a table using a user-defined function 在 sql 中使用用户定义的表类型时出错 --> 操作数类型冲突:varchar 与“用户定义的表类型”不兼容 - Error while using user-defined table type in sql --> Operand type clash: varchar is incompatible with "user defined table type" 操作数类型冲突:nvarchar与用户定义的表类型不兼容 - Operand type clash: nvarchar is incompatible with user-defined table type 我可以用用户定义的表类型构造表吗? - Can I construct a table with the user-defined table type? 使用用户定义的函数动态更新临时表和数据库表条目 - Using user-defined functions to dynamically update temp tables and database table entries 使用 JDBC 将用户定义的表类型传递给 SQL Server 存储过程 - Passing a user-defined table type to a SQL Server stored procedure using JDBC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM