【问题标题】:Error in stored procedure in SQL Server 2008SQL Server 2008 中的存储过程错误
【发布时间】:2016-05-25 15:31:00
【问题描述】:

我创建了一个名为detalleList 的类型,我需要在存储过程中使用它,但出现错误。我做错了什么?

这是detalleList 类型

CREATE TYPE [dbo].[detalleList] 
AS TABLE ([idCcompVtaD] [bigint] NULL,
          [idProducto] [bigint] NULL,
          [cantidad] [int] NULL,
          [precio] [decimal](18, 2) NULL,
          [precioTotal] [decimal](18, 2) NULL)

CREATE PROCEDURE [dbo].[SP_GrabarFactura]
    @List as dbo.detalleList readonly,
    @Fecha datetime,
    @total decimal(18,2),
    @notas varchar(200),
    @idUsuario bigint,
    @idCliente bigint,
    @new_identity INT = NULL OUTPUT
AS
BEGIN
    SET NOCOUNT ON;

    INSERT INTO ccompvta (fecha, total, notas, idUsuario, idCliente) 
    VALUES (@Fecha, @total, @notas, @idUsuario, @idCliente);

    SET @new_identity = SCOPE_IDENTITY();

    INSERT INTO dcompvta (idCcompVta, idProducto, cantidad, precio, precioTotal)  
        SELECT 
            (@new_identity, 
            idProducto, cantidad, precio, precioTotal) 
        FROM @list;
END

错误:

消息 102,级别 15,状态 1,过程 SP_GrabarFactura,第 19 行
Sintaxis wronga cerca de ','。

【问题讨论】:

标签: sql sql-server sql-server-2008 stored-procedures types


【解决方案1】:

在最后一行你有太多的括号:

select (@new_identity, idProducto,cantidad,precio, precioTotal) from @list;

应该是

select @new_identity, idProducto,cantidad,precio, precioTotal from @list;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-26
    • 1970-01-01
    • 2018-10-04
    • 2012-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多