Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2003
    Posts
    41

    Unanswered: How to execute SQL code on the condition that a variable is NULL

    Hi again =) Have a quick and easy question. I have a query which I am assigning the result of to a local varibale within a stored procedure. I want to then look at the variable and exit the sproc if it is undefined/null.

    Here's a snippet

    ------
    SET @parentId = (SELECT msParentId FROM tblMasterSite WHERE (msId = @root) AND (msRootId <> msParentId))
    IF @parentId = ''
    BEGIN
    RETURN
    END
    ------

    The problem is that even when no value is assigned to @parentId the IF statement still doesn't fire. How can I check if @parentId was assigned a value?

  2. #2
    Join Date
    Feb 2003
    Posts
    41
    Well, I just figured out my simple problem. Replacing @parentId <> '' with @parentId IS NULL fixed everything up perfectly.

    =)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •