Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!
Become a Premium Member and unlock a new, free course in leading technologies each month.
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
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)
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)
Declare @s int
SET @s = @a + @b + @c + @d
SELECT * FROM table
WHERE
a = CASE WHEN @s = 0 THEN a WHEN @a = 1 THEN 1 ELSE 2 END
OR b = CASE WHEN @s = 0 THEN b WHEN @b = 1 THEN 1 ELSE 2 END
OR c = CASE WHEN @s = 0 THEN c WHEN @c = 1 THEN 1 ELSE 2 END
OR d = CASE WHEN @s = 0 THEN d WHEN @d = 1 THEN 1 ELSE 2 END
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.