Reputation: 881
I am coding a Table-valued Function in MS SQL 2008 R2.
Is it possible for a partial string of an SQL statement, which is in the WHERE clause to wrap an IF construct?
WHERE MyTable.MyColumn = @MyVariable
AND (MyColumn2 = @MyVariable2)
ORDER BY MyTable.MyColumn DESC
Upvotes: 2
Views: 113
Reputation: 51494
You can use
WHERE MyTable.MyColumn = @MyVariable
AND ((@date is null) or (MyColumn2 = @MyVariable2))
Upvotes: 1