【发布时间】: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 ','。
【问题讨论】:
-
过程定义中的“as”看起来很奇怪。
-
旁注:您应该不为您的存储过程使用
sp_前缀。微软有reserved that prefix for its own use (see Naming Stored Procedures),你确实会在未来某个时候冒着名称冲突的风险。 It's also bad for your stored procedure performance。最好只是简单地避免sp_并使用其他东西作为前缀 - 或者根本不使用前缀!
标签: sql sql-server sql-server-2008 stored-procedures types