title: Nested if else statement
body: <p>I am creating a function to return '0' or '1' depending on the result of nested if else statements. Using MSSQL.</p>
  
  <pre><code>ALTER FUNCTION udf_check_names_starting_with_quotationmark
  (@string NVARCHAR(100))
  RETURNS INT
  AS
  BEGIN
    DECLARE @condition INT
    SET @string = LTRIM(@string)
    SET @string = RTRIM(@string)
  
    IF (PATINDEX('"%', @string) !=0)
      BEGIN
        SET @condition = 1
      END
    ELSE IF (PATINDEX('%"%', @string) !=0) 
      BEGIN
        SET @condition=1
      END
    ELSE IF (PATINDEX('%"', @string) !=0)
      BEGIN
        SET @condition = 1
      END
    ELSE
      BEGIN
        SET @condition=0
      END
    RETURN @condition
  END
  </code></pre>
  
  <p>Everything is working fine with this. Is there a better way to achieve this (I have tried using OR but SQL editor showing an error, not recognizing the OR).</p>