複数のセクションがあり、セクションごとに N 個の質問があるアンケートがあります。各セクションには、10 の質問がページに表示されます。Answers
を使用して名前を付けたテーブルに 10 個の質問のセットの結果を保存していfor loop
ます。また、パイプラインに次のセクションをロードするために、すべての質問に回答したときに実行中のセクションを無効にする基準があります。
テーブル 'Answers' に 10 個の質問を送信すると、トリガーを使用して 'QuestionMaster' マスター テーブル内の質問の総数をカウントし、質問は に保存されAnswers
ます。2 つが等しい場合、現在のセクション ステータスは false になり、次のセクションが選択されます。
私のトリガーは:
ALTER Trigger [dbo].[GetAnsweredQuestionCount]
On [dbo].[Answers]
After Insert
As
Begin
Declare @sectionid as int
Declare @companyid as int
Declare @Count_Inserted as int
Declare @Count_remaining as int
Declare @userid as varchar(50)
Set @sectionid = (Select Top(1) SectionId from inserted)
Set @companyid = (Select Top(1) CompanyId from inserted)
Set @userid= (Select Top(1) UserId from inserted )
Set @Count_inserted = (Select count(id) from inserted where SectionId = @sectionid and companyid = @companyid and userid=@userid)
Set @Count_remaining = (Select count(id) from SectionQuestionMap where SectionId = @sectionid and companyid = @companyid and userid=@userid)
If @Count_inserted = @Count_remaining
begin
Update SectionCompanyRateMap Set IsCompleted =1 Where SectionId=@sectionid and CompanyId=@companyid
end
End
私の問題は、ループを使用してレコードを挿入しているため、トリガーが10回も発生することです。これは望ましくありません。すべての質問が保存されたときに一度だけ実行されるように、最初の 9 回のトリガーをスキップする方法があることを知りたいです。