Thursday, February 4, 2010

HOW TO USE IF ELSE IN PROC

ALTER PROCEDURE [dbo].[360LMS_DashBoard]

@UserID int,
@temp int

AS

if @temp=1
begin

Declare @tempUinfo TABLE
(sr smallint IDENTITY Primary Key,
MyFullName nvarchar(50),
CollegeName nvarchar(50),
Faculty nvarchar(50),
EmailID nvarchar(20),
MobileNumber nvarchar(20),
RegistrationDate datetime
)
INSERT INTO @tempUinfo

select FirstName+' '+MiddleName+' '+LastName as MyFullName,CollegeName,Faculty,EmailID,MobileNumber,
RegistrationDate from [360LMS_Users] where UserID=@UserID

select sr,MyFullName,CollegeName,Faculty,EmailID,MobileNumber,Convert(varchar,RegistrationDate,100) as

RegistrationDate from @tempUinfo
end


else if @temp=2
begin

Declare @tempCCStatus TABLE
(sr smallint IDENTITY Primary Key,
CourseTitle nvarchar(50),
ModuleName nvarchar(50),
LastAccessDate nvarchar(50),
TotalAccessTime nvarchar(50),
LessonStatus nvarchar(50)
)
INSERT INTO @tempCCStatus
select'Certified Course In Information Security' as CourseTitle,cd.CourseTitle as ModuleName,
sco.SuspendData as LastAccessDate,sco.TotalTIme as TotalAccessTime,sco.LessonStatus
from [360LMS_Users] as u,[LearnGrid_UserCourses] as uc,[LearnGrid_CourseData] as cd,[LearnGrid_UserSCOData]

as sco
where u.UserID=uc.UserID and uc.CourseID=cd.CourseID and uc.EventID=sco.EventID and u.UserID=@UserID

select sr,CourseTitle,ModuleName,Convert(varchar,LastAccessDate,100) as

LastAccessDate,TotalAccessTime,LessonStatus from @tempCCStatus
end

No comments:

Post a Comment