Add column to condition based on parameter value SQL

A Coder

I'm working in a dynamic query where i need to add a column to the query if the parameter value is false.

//SQL:

SET @FilterExp = 'SELECT * from tblName where ptblnFlag = '+Convert(varchar(2),@blnFlag)+') as tbl where 1=1'+ COALESCE(NULLIF( CONVERT(varchar(8000), @FilterExp),''), '')

In the above query i need to check if the @blnFlag is false then the column can be added in the where condition. If true it need not to be there.

Something like if the condition is false it should return all values and if true the result set is based on the condition.

Pரதீப்

You just need AND/OR operator's no need of Dynamic query here

SELECT *
FROM   tblName
WHERE  ( ptblnFlag = @blnFlag
         AND @blnFlag = 0 )
        OR @blnFlag = 1 

May be am wrong with variable names but logic will be same

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Add column based on condition

From Dev

How to add a condition in GROUP BY based on the number of rows with a certain column value?

From Dev

SQL query add custom value to select based on distinct column value

From Dev

Add value based on column value and group in SQL query.

From Dev

Replace value in column based on a condition

From Dev

Add a column based on a condition from other columns

From Dev

Add rows based on a column value

From Dev

pandas add column to dataframe having the value from another row based on condition

From Dev

Assign value to group based on condition in column

From Dev

Extract column name and specific value based on a condition

From Dev

change where condition based on column value

From Dev

concatenate a column value for several rows based on condition

From Dev

Extract column name and specific value based on a condition

From Dev

How to add new column from another table based on a condition in sql server

From Dev

Create new column based on condition in sql?

From Dev

pig to add column based on value in another column

From Dev

MySQL first select column based on parameter value and then value of column

From Dev

MySQL first select column based on parameter value and then value of column

From Dev

Sql server filter by different column based on parameter

From Dev

SQL Server : set a row value based on a condition

From Dev

Populating a column based on value of another column (SQL)

From Dev

How to use column value in sql comparison condition

From Dev

Assign value to a column from another column based on condition

From Dev

pandas apply condition to column value based on another column

From Dev

In JSF is there a way to add a passThroughAttribute to a component based on a condition or parameter?

From Dev

Conditional WHERE based on SQL Server parameter value

From Dev

Sqlite add column based on another columns value

From Dev

pandas add rows based on column value

From Dev

Add data to csv column based on row value

Related Related

  1. 1

    Add column based on condition

  2. 2

    How to add a condition in GROUP BY based on the number of rows with a certain column value?

  3. 3

    SQL query add custom value to select based on distinct column value

  4. 4

    Add value based on column value and group in SQL query.

  5. 5

    Replace value in column based on a condition

  6. 6

    Add a column based on a condition from other columns

  7. 7

    Add rows based on a column value

  8. 8

    pandas add column to dataframe having the value from another row based on condition

  9. 9

    Assign value to group based on condition in column

  10. 10

    Extract column name and specific value based on a condition

  11. 11

    change where condition based on column value

  12. 12

    concatenate a column value for several rows based on condition

  13. 13

    Extract column name and specific value based on a condition

  14. 14

    How to add new column from another table based on a condition in sql server

  15. 15

    Create new column based on condition in sql?

  16. 16

    pig to add column based on value in another column

  17. 17

    MySQL first select column based on parameter value and then value of column

  18. 18

    MySQL first select column based on parameter value and then value of column

  19. 19

    Sql server filter by different column based on parameter

  20. 20

    SQL Server : set a row value based on a condition

  21. 21

    Populating a column based on value of another column (SQL)

  22. 22

    How to use column value in sql comparison condition

  23. 23

    Assign value to a column from another column based on condition

  24. 24

    pandas apply condition to column value based on another column

  25. 25

    In JSF is there a way to add a passThroughAttribute to a component based on a condition or parameter?

  26. 26

    Conditional WHERE based on SQL Server parameter value

  27. 27

    Sqlite add column based on another columns value

  28. 28

    pandas add rows based on column value

  29. 29

    Add data to csv column based on row value

HotTag

Archive