Thursday, February 4, 2010

HOW TO USE TRIGGER ON TABLE OR AFTER TRIGGER (AFTER REGISTRATION ALL COURSES WILL ASSIGNS TO USERS)

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[trigRegUser] ON [dbo].[360LMS_Users]
FOR INSERT AS

declare @intUserID int
declare @intCourseID int
declare @bitDebug bit
declare @dtRegistratioDate datetime
declare @intEventID int

set @bitDebug = 0
set @dtRegistratioDate = GETDATE()
set @intUserID=(select max(UserID) from [360LMS_Users] )
declare @Identifier nvarchar(50)
declare @LessonStatus nvarchar(50)
declare @SCOExit nvarchar(50)
declare @SCOEntry nvarchar(50)
declare @RawScore int
declare @PreTestScore int
declare @PostTestScore int
declare @SuspendData nvarchar(50)
declare @Credit nvarchar(50)
declare @TotalTIme nvarchar(50)

set @Identifier = 1
set @LessonStatus = 'not attempted'
set @SCOExit = NULL
set @SCOEntry = 'ab-initio'
set @RawScore = 0
set @PreTestScore = 0
set @PostTestScore = 0
set @SuspendData = NULL
set @Credit = 'Information Security'
set @TotalTIme = '00:00:00'

/*get all courses*/
DECLARE curTempCourseID Cursor Fast_Forward for
SELECT CourseID from LearnGrid_CourseData
Open curTempCourseID
fetch next from curTempCourseID into @intCourseID
While @@Fetch_Status = 0
BEGIN
exec [360LMS_UserCoursesAdd] @intUserID,@intCourseID,@bitDebug,@dtRegistratioDate set @intEventID =

@@IDENTITY

exec [360LMS_UserSCODataAdd] @intEventID,@Identifier ,@LessonStatus,@SCOExit ,@SCOEntry ,@RawScore

,@PreTestScore , @PostTestScore ,@SuspendData ,@Credit ,@TotalTIme

fetch next from curTempCourseID into @intCourseID
END
CLOSE curTempCourseID
DEALLOCATE curTempCourseID

No comments:

Post a Comment