Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How to use IF-ElSE in 'WITH' clause

$
0
0

Hi,

 I wonder if i can use IF-ELSE in 'With' clause; as follows

;WITH TEST  
    AS(
       --my select statement
    )
    IF parameter >0
        BEGIN      
            --select statement on TEST with some condition
        END
    ELSE
        BEGIN   

           --select statement on TEST with some other condition

        END   

I tried the same but i got Syntax error message.

Is the scenario possible or i shall use a temp table?

Please Suggest.

Thank you,

Shubham


shubham


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>