differentiating odd and even numbers in a table

I need to be able to tell if a number is even or odd
I tried this but it is giving errors
I am trying to create a UDF

BEGIN
      DECLARE @rate int
      if @proj_no = ((@proj_no % 2)=0) set @rate = 2
      else set @rate = 1
      RETURN @rate
END

The errors are
Msg 102, Level 15, State 1, Procedure nRate, Line 6
Incorrect syntax near '='.
Msg 156, Level 15, State 1, Procedure nRate, Line 7
Incorrect syntax near the keyword 'else'.
TagomAsked:
Who is Participating?
 
cyberkiwiConnect With a Mentor Commented:
BEGIN
      DECLARE @rate int
      set @rate = case when (@proj_no % 2)=0 then 2 else 1 end
      RETURN @rate
END
0
 
TagomAuthor Commented:
Thanks
I was almost there this worked great
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.