Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a sql query, say of the following form:
select a, b, c from table t where t.a = "hello" and t.b = "there" and t.c = "world" group by a,b,c
I would like to have a Boolean condition (d == true) to determine the computation above such that when say d is set to true, the above query get executed, and when d is false, the query gets reduced to the following and compiled:
select a, b from table t where t.a = "hello" and t.b = "there" group by a,b.

Any suggestions as to how this could be achieved using oracle 11g (sql/pl-sql/t-sql)?

What I have tried:

I have tried a simple logic of setting the flag and executing the query but I need to conditionally compile part of the query based on a preset condition.
Posted
Updated 16-Aug-16 17:48pm
Comments
Kornfeld Eliyahu Peter 16-Aug-16 16:17pm    
What about IF?
David_Wimbley 16-Aug-16 16:17pm    
I'm assuming the boolean condition D is passed in/not a column of the table T?

If so, in t-sql you can just do something like

DECLARE @d BIT = 1;


IF(@d = 1)
SELECT 'D Condition is true, run expanded query';
ELSE
SELECT 'D Condition is false, run condensed query';

But i may not be quite understanding your issue.
Member 12189753 16-Aug-16 16:37pm    
@David_Wimbley: that makes sense. but this could be unwieldy if the query I much longer. the question I have is a more extensive one. we run a longer production sql in general simplified version of which I have posted in the question. as we are making enhancements, to add in more columns, clauses (where and groupby), which in turn have case statements and conditional logic, etc, we need to omit out the adds/enhancements depending on the system/business line to customize the query per user/group. I am looking for a way either procedurally or using some form of transact or straight sql way to establish this customization.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900