就是说,当插入商品时,取得了这个商品的目录ID1,然后再根据这个目录的ID1,把这个目录的ID1的所有父ID都插入到另外的一个目录表中(如果这个目录表的目录ID,只包括目录ID1中的一些父ID,只也把目录ID的父ID插入到另外的一个表中,直到这个另外的一个表的ID的父ID与要插入到这个ID1为止

解决方案 »

  1.   

    还是自己写出来,大家都好看一下,有什么要改的
    但我不知道是否正确
    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