SQLTeam.com | Weblogs | Forums

Help with where statement

I need help in where statement,

where Stud_name = @var1
if @var1 is null or empty, should pull records for all Students, not sure how to use 1 = 1 in this case


WHERE ((@var1 IS NULL OR @var1 = '') OR Stud_name = @var1)

I would enforce either NULL or blank in the variable - and simplify the check to that value. For example:

SET @var1 = COALESCE(@var1, '');

  FROM ...
 WHERE (@var1 = '' OR Stud_Name = @var1)

thank you both of you, I will try now!!