Wednesday, April 4, 2012

If and Else in SQL.....


CREATE PROCEDURE [dbo].[GetFilterData]
-- Add the parameters for the stored procedure here
@CourseLibraryCategoryID int,
@Search nvarchar(50),
@LanguageTypeId nvarchar(50)
AS
BEGIN
if @CourseLibraryCategoryID!=0
begin
select * from TrainingCourses TC LEFT JOIN TrainingSkins TS ON TC.[SkinID] = TS.[SkinID]   where CourseID in(select CourseID from CourseCategory where CategoryID=@CourseLibraryCategoryID)
end

else if @LanguageTypeId!=''
begin
select * from TrainingCourses TC LEFT JOIN TrainingSkins TS ON TC.[SkinID] = TS.[SkinID] where   TC.[LanguageTypeID]= @LanguageTypeId
        end

else
begin
select * from TrainingCourses TC LEFT JOIN TrainingSkins TS ON TC.[SkinID] = TS.[SkinID] where  TC.[CourseName] Like '%'+@Search + '%'
     end
END

0 comments:

Post a Comment