what is the different ? THE RESULT IS SAME . but if i use my sql ,even vflag =0 or 1 it also select all county is HK my expected result when v flag =1,only filter id =001 or 002 and country is HK HOW TO DO ?
HOW CAN I DO IT IN A SQL ONLY?? as i have many filtering criteria, and if condition , it can causes too many combination to write different sql to meet our needs.
-_-
Member
375 Points
1033 Posts
sql question (oracle)
Jan 18, 2013 02:06 PM|LINK
i have create a package, and a variable v_flag
if v_flag=1 then i would like to add a filter to select id=001 or 002 to the sql. else just ignore this filtering in sql.
how can i do that?
here is my sql but output is out of my expectation:
select * from customer
where ((v_flag=1 and (id='001' or id='002') or v_flag=0) and
country='HK';
kraznodar
Contributor
3332 Points
881 Posts
Re: sql question (oracle)
Jan 18, 2013 03:49 PM|LINK
Try
select * from customer
where ((v_flag=1 and (id='001' or id='002')) or v_flag=0) and
country='HK');
This assumes that you want only HK for country. Any v_flag=0 will return and if v_flag=1 then if id='001' or '002' it will return.
-_-
Member
375 Points
1033 Posts
Re: sql question (oracle)
Jan 20, 2013 04:02 AM|LINK
-_-
Member
375 Points
1033 Posts
Re: sql question (oracle)
Jan 20, 2013 01:06 PM|LINK
anyone helps??
ramramesh
Member
458 Points
158 Posts
Re: sql question (oracle)
Jan 20, 2013 01:26 PM|LINK
Use If else conditions
for
http://learnsqlserver.in/2/IF-ELSE-CONDITION.aspx
-_-
Member
375 Points
1033 Posts
Re: sql question (oracle)
Jan 20, 2013 03:53 PM|LINK
HOW CAN I DO IT IN A SQL ONLY?? as i have many filtering criteria, and if condition , it can causes too many combination to write different sql to meet our needs.
kraznodar
Contributor
3332 Points
881 Posts
Re: sql question (oracle)
Mar 13, 2013 09:00 PM|LINK
Select * from customer
where country = 'HK' And ((v_flag = 1 and id In ('001','002')) Or v_flag = 0);
This will return only HK country entries and only where v_flag = 0 or v_flag = 1 and ID = '001' or '002'