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.