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

Error while using if else in where clause

$
0
0

I am passing two variables like SDate and EDate to stored procedure and I want select data from table whereVDate is betwwen SDate and EDate if both SDate and EDate is not null .If EDate is null then I want to select data where VDate = SDate.I have tried using If..Else andCase in where clause but it was giving incorrect syntx error. Query :

SELECT
    Column1 ,column2fromTable twhere t.VDate IN(If EDate ISNOTNULLSELECT
        VDate FROMTablewhere VDate BETWEEN SDate AND EDateELSE
     SDate)

Any help would be appreciated.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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