This is better handled in a stored procedure but here is the sequence you could use

```
declare @sql varchar(max)
declare @a int ,@b int , @c int , @d int
set @sql = '';
if @a = 1
set @sql = 'WHERE a = 1'
if @b = 1
if @sql <> ''
set @sql = 'AND b = 1'
else
set @sql = 'WHERE b = 1'
if @c = 1
if @sql <> ''
set @sql = 'AND c = 1'
else
set @sql = 'WHERE c = 1'
if @d = 1
if @sql <> ''
set @sql = 'AND d = 1'
else
set @sql = 'WHERE d = 1'
set @sql = 'SELECT * FROM TABLEA ' + @sql
exec(@sql)
```