1

大家好,我是新手,所以在这里遇到了一些麻烦

我有两张这样的桌子

错误

BugID|Title|ProjectName|CreatedBy

错误历史

BughistoryID|BugID|Assignedto|ToStatus|FromStatus

我想为要插入到表中的表编写一个插入存储过程,并具有Bugs标识和主键。[Title]|[ProjectName][CreatedBy]bugsBugID

之后,我必须将BugID新标题的Tostatus插入到BugHistory表格中。这两个步骤应该在一个存储过程中完成。

我想要一个选择语句,我必须在 gridview 中显示 bugs 表,其中包含表中[AssignedTo][Tostatus]BugHistory。请问我如何为这两个过程使用函数?

4

2 回答 2

0

尝试在您的 Bugs 中创建一个触发器以在您的 BugsHistory AFTER INSERT 之后插入数据

于 2012-07-30T05:01:25.433 回答
0

尝试这样的事情:

-- create stored procedure to insert a new bug, with parameters
CREATE PROCEDURE dbo.InsertBug 
    @Title VARCHAR(100),
    @ProjectName VARCHAR(100),
    @CreatedBy VARCHAR(100)
AS BEGIN

  -- variable to hold newly inserted "BugID"    
  DECLARE @NewBugID INT

  -- do the insert into the "Bugs" table      
  INSERT INTO dbo.Bugs(Title, ProjectName, CreatedBy)
  VALUES(@Title, @ProjectName, @CreatedBy)

  -- get the new BugID that's been assigned during INSERT      
  SELECT @NewBugID = SCOPE_IDENTITY()

  -- insert into the BugHistory table - since you didn't specify anything,
  -- I assumed the bug gets assigned to whoever created it by default,
  -- and I assumed "ToStatus" is a string column so I assigned "New" to it
  -- ADAPT as needed !
  INSERT INTO dbo.BUgHistory(BugID, AssignedTo, ToStatus)
  VALUES(@NewBugID, @CreatedBy, 'New')
END
于 2012-07-30T05:07:29.863 回答