Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2006
    Posts
    111

    Unanswered: Conditional Execute

    How do I properly write the following?

    IF(@ParamVar > 0)
    Execute SELECT * FROM TABLE1
    ELSE
    Execute SELECT * FROM TABLE1 UNION SELECT * FROM TABLE2

    Thank you!

  2. #2
    Join Date
    Dec 2008
    Posts
    135
    IF(@ParamVar > 0)
    SELECT * FROM TABLE1
    ELSE
    begin
    SELECT * FROM TABLE1
    UNION
    SELECT * FROM TABLE2
    end

  3. #3
    Join Date
    Dec 2008
    Posts
    135
    r u can use like this too
    IF(@ParamVar > 0)
    Execute ('SELECT * FROM TABLE1')
    ELSE
    Execute ('SELECT * FROM TABLE1 UNION SELECT * FROM TABLE2')

    rememeber while using union the select columns should be same no of columns and same datatype

  4. #4
    Join Date
    Jul 2006
    Posts
    111

    muchos gracias

    i've been attacking the problem from the wrong perspective, all the while i thought its got to do with EXECUTE when what I needed was BEGIN---END.

Posting Permissions

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