user3767613
user3767613

Reputation: 123

Error in stored procedure in SQL Server 2008

I created a type named detalleList and I need to use it in a stored procedure but I get an error. What am I doing wrong?

This is detalleList type

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

Error:

Msg 102, Level 15, State 1, Procedure SP_GrabarFactura, Line 19
Sintaxis incorrecta cerca de ','.

Upvotes: 0

Views: 73

Answers (1)

Gottfried Lesigang
Gottfried Lesigang

Reputation: 67311

In the last line you have some parenthesis too much:

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

Should be

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

Upvotes: 2

Related Questions