Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!
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
Title | # Comments | Views | Activity |
---|---|---|---|
SQL Get Store Procedure Column Name As Row | 5 | 39 | |
SQL Server Express automatically execute SQL or SP | 8 | 32 | |
How can I retrieve the column names from a T-SQL table? | 2 | 16 | |
T-SQL: How to extract records into a new table | 6 | 11 |
Join the community of 500,000 technology professionals and ask your questions.