还是自己写出来,大家都好看一下,有什么要改的 但我不知道是否正确 ALTER PROCEDURE AddStoreProduct ( @ProductID INT, @StoreID VARCHAR(10) ) AS begin tran AddStoreProduct declare @CategoryID int declare @Categories_CategoryID int declare @StoreCategoryID intset @CategoryID=(Select CategoryID from CMRC_Products where ProductID=@ProductID)INSERT INTO SPProducts(StoreID,ProductID,CategoryID)values(@StoreID,@ProductID,@CategoryID)set @Categories_CategoryID=(Select CMRC_Categories_CategoryID from CMRC_Categories where CategoryID=@CategoryID)set @StoreCategoryID=(Select CategoryID from SPCategories where StoreID=@StoreID AND CategoryID=@CategoryID)begin while (@StoreCategoryID<>@CategoryID) begin INSERT INTO SPCategories(StoreID,CategoryID,Categories_CategoryID) values(@StoreID,@CategoryID,@Categories_CategoryID) set @StoreCategoryID=(Select CategoryID from SPCategories where StoreID=@StoreID AND CategoryID=@Categories_CategoryID) set @CategoryID=@Categories_CategoryID set @Categories_CategoryID=(Select CMRC_Categories_CategoryID from CMRC_Categories where CategoryID=@Categories_CategoryID) end end
但我不知道是否正确
ALTER PROCEDURE AddStoreProduct
(
@ProductID INT,
@StoreID VARCHAR(10)
)
AS
begin tran AddStoreProduct
declare @CategoryID int
declare @Categories_CategoryID int
declare @StoreCategoryID intset @CategoryID=(Select CategoryID from CMRC_Products where ProductID=@ProductID)INSERT INTO SPProducts(StoreID,ProductID,CategoryID)values(@StoreID,@ProductID,@CategoryID)set @Categories_CategoryID=(Select CMRC_Categories_CategoryID from CMRC_Categories where CategoryID=@CategoryID)set @StoreCategoryID=(Select CategoryID from SPCategories where StoreID=@StoreID AND CategoryID=@CategoryID)begin
while (@StoreCategoryID<>@CategoryID)
begin
INSERT INTO SPCategories(StoreID,CategoryID,Categories_CategoryID) values(@StoreID,@CategoryID,@Categories_CategoryID)
set @StoreCategoryID=(Select CategoryID from SPCategories where StoreID=@StoreID AND CategoryID=@Categories_CategoryID)
set @CategoryID=@Categories_CategoryID
set @Categories_CategoryID=(Select CMRC_Categories_CategoryID from CMRC_Categories where CategoryID=@Categories_CategoryID)
end
end