Sql server 插入多行作为参数-存储过程
我有两张桌子,发票和一些物品 我正在使用存储过程将数据插入发票表。发票应包含多个项目。下面是我用来在发票表中插入一行的存储过程Sql server 插入多行作为参数-存储过程,sql-server,vb.net,stored-procedures,Sql Server,Vb.net,Stored Procedures,我有两张桌子,发票和一些物品 我正在使用存储过程将数据插入发票表。发票应包含多个项目。下面是我用来在发票表中插入一行的存储过程 @InvoiceDate date, @Vno int, @Vdate date, @ClientId int, @ItemId int, @Discount bigint, @InvoiceID int, @CreditAmount bigint, @CreditDate date, @CreditType varchar(15), @Quantity int, @I
@InvoiceDate date,
@Vno int,
@Vdate date,
@ClientId int,
@ItemId int,
@Discount bigint,
@InvoiceID int,
@CreditAmount bigint,
@CreditDate date,
@CreditType varchar(15),
@Quantity int,
@InvoiceQuantity int
AS
Insert Invoice
([Invoice Date], [Voucher No], [Voucher Date], ClientID, ItemId, Discount, Quantity)
VALUES (@InvoiceDate, @Vno, @Vdate, @ClientID, @ItemId, @Discount, @InvoiceQuantity)
SET @InvoiceID = SCOPE_IDENTITY()
Insert Credits
(CreditAmount, CreditDate, ClientID, [Invoice Id], [Credit Type])
VALUES (@CreditAmount, @CreditDate, @ClientID, @InvoiceID, @CreditType)
update Items set ItemQuantity = ItemQuantity - @Quantity where ItemID = @ItemId
问题是我不能在我的表中插入多个项,因为我正在为此使用参数'@ItemId'。我不能为“ItemId”使用多个参数,因为项目的数量不同,并且用户将在运行时选择项目
我正在使用SQL Server数据库。此存储过程正在VB.Net的Windows窗体应用程序中使用。查看表值参数。您不能通过单个INT参数发送多个INT值,也不能从客户端程序调用在循环中添加项,即使涉及到多个往返。