AND operation in WHERE clause if IF condition satisfy : <p>Suppose I have a variable <code>@hasAge</code> which can have value either <code>1</code> or <code>0</code>.</p>

<p>I want to write a SELECT query with where clause in which I want to check certain condition if <code>@var</code> is 1 otherwise I don't want to check that condition.
Something like this:</p>

<pre><code>SELECT * FROM My_Table mt
WHERE mt.name = 'abcd'
AND
IF(@hasAge)
mt.age &gt; 10 
</code></pre>

<p>So I want to compare my.age > 10 only if <code>@hasAge</code> is <code>1</code></p>

<p>I dont want to have 2 different select statement like this:</p>

<pre><code>if(@hasAge)
BEGIN
SELECT * FROM My_Table mt
    WHERE mt.name = 'abcd'
    AND
    mt.age &gt; 10
ELSE
BEGIN
SELECT * FROM My_Table mt
    WHERE mt.name = 'abcd'
END
</code></pre>
