我有一个过程,我将在下面写。现在我想添加两个选择。两个选择和两个插入一个SQL Server存储过程
首先,SELECT ID FROM Category Where CategoryName = ''
将其保存在变量@CategoryID
中。
第二选择语句:SELECT ID FROM Type WHERE TypeName = ''
并将其保存在@TypeID
中。
现在我想添加第二个插入:
INSERT INTO Inventory(ProductID, InputQuantity, Margin, InputDateTime, ExpDate)
VALUES(@ProductID, @Quantity,@Margin, @InputDateTime, @ExpDate)
where ProductID = Scope_Identity()
谢谢:)
这是我的程序:
USE [AcidDB]
GO
/****** Object: StoredProcedure [dbo].[InsertProducts] Script Date: 03/24/2011 15:29:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[InsertProducts]
@CategoryID int,
@TypeID int,
@BarCode NvarChar(MAX),
@ArtNumber NvarChar(MAX),
@ProductName NvarChar(MAX),
@Price Decimal(18, 2),
@SelfPrice Decimal(18, 2),
@PriceWithOutAWD Decimal(18, 2),
@UnitsInStock int,
@Comment NvarChar(MAX)
AS
INSERT INTO Products(CategoryID, TypeID, BarCode, ArtNumber, ProductName, Price, SelfPrice, PriceWithOutAWD, UnitsInStock, Comment)
VALUES(@CategoryID, @TypeID, @BarCode, @ArtNumber, @ProductName, @Price, @SelfPrice, @PriceWithOutAWD, @UnitsInStock, @Comment)
Exec InsertProducts '','','','','','','','','',''
Select SCOPE_IDENTITY()
你的问题是什么? – 2011-03-24 13:11:53
我怎样才能得到这个选择并在这个过程中插入statmant? – 2011-03-24 13:14:44
我认为你需要在你的脚本中使用“GO”。目前它会自动递归调用。 – 2011-03-24 13:19:14