#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    22
    Rep Power
    0

    If with variable in Where Clause


    In Stored Procedure
    Variable @offnum (integer)
    is passed either a number or nothing
    how can I do this for my where clause:

    If (@offnum) Is Null
    (Employee.Empoff like '%')
    Else
    (Employee.Empoff = @offnum)
    End

    If I leave it as null I don't get what I want.

    Edit -Or it could be
    If NOT @offnum is Null
    (Employee.Empoff = @offnum)
    with no else, just ignore it if it's null

    Thank you.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    22
    Rep Power
    0
    I found a solution after a few hours of searching -

    AND (@offnum Is Null OR Employee.Empoff = @offnum)

IMN logo majestic logo threadwatch logo seochat tools logo