Multiple WHERE clauses
Greetings everyone,
I was struggling with a question I was hoping someone could help with...
I am trying to query a database using a select query and want to filter the results to only show me records between certain dates and when a specific values appear in another field.
I am do each on their own by cannot seem to combine the two here is my code that doesn't work...
select * from sdfd.MSF228
where CURR_DUE_DATE between 20140515 and 20140522
AND
PREQ_STK_CODE = 007191010 OR
PREQ_STK_CODE = 007191010 OR
PREQ_STK_CODE = 009662316 OR
PREQ_STK_CODE = 007191015 OR
PREQ_STK_CODE = 007160066 OR
PREQ_STK_CODE = 007160039 OR
PREQ_STK_CODE = 009663310 OR
PREQ_STK_CODE = 007160076 OR
PREQ_STK_CODE = 007180076 OR
PREQ_STK_CODE = 007180004 OR
PREQ_STK_CODE = 007180006
Can anyone help please?
Thanks,
Pete
Hello Pete,
boolean logic: OR before AND, that's why it's not working. Use brackets for the OR part:
select * from sdfd.MSF228
where CURR_DUE_DATE between 20140515 and 20140522
AND
PREQ_STK_CODE = 007191010 OR
PREQ_STK_CODE = 007191010 OR
PREQ_STK_CODE = 009662316 OR
PREQ_STK_CODE = 007191015 OR
PREQ_STK_CODE = 007160066 OR
PREQ_STK_CODE = 007160039 OR
PREQ_STK_CODE = 009663310 OR
PREQ_STK_CODE = 007160076 OR
PREQ_STK_CODE = 007180076 OR
PREQ_STK_CODE = 007180004 OR
PREQ_STK_CODE = 007180006
Or to shorten it you can use the
IN Operator:
select * from sdfd.MSF228
where CURR_DUE_DATE between 20140515 and 20140522
AND
PREQ_STK_CODE IN (007191010, 007191010, 009662316, 007191015, 007160066
,007160039, 009663310, 007160076, 007180076, 007180004, 007180006)
Olaf Helper
[ Blog] [ Xing] [ MVP]
Similar Messages
-
Join and Multiple where clauses: which is better??
There was an argument between a colleague and I. He prefers building his views joining many tables with many where clause while I am cute with my join which is simpler and more understandable for me. So, it started an argument on which is a superior way of joining tables.
I will actually like to know we is faster and better: using JOINs or using multiple where clauses to retrieve values from multiple tables.?Dave:
"Are we talking about the difference between Oracle Joins and ANSI Joins?
e.g.
Select d.dept_name, e.emp_name
from dept d, emp e
where d.dept_id = e.dept_id"
That is not really an "Oracle Join". That syntax works on just about every SQL database I have ever worked with. The (+) syntax for an outer join is Oracle specific, but some other databases use a similar style for outer joins (something like a.c += b.c or a.c *= b.c).
OP:
There are things you can do with the ANSI style syntax that either cannot be done, or cannot be done as easily, with Oracle's syntax. Most notably, outer joining one table to more than one other tables, and FULL OUTER joins.
Having said that, in my experience, both are rather rare occurrences, so I tend to stick to doing the jopins in the WHERE clause because that is what I am used to.
John -
"Invalid Column" on multiple where clauses with subqueries and cfqueryparam
I'm seeing a behavior in the coldfusion cfquery that I'd like to find an exmplanation for . I've got a query that does a subquery in the select portion and if I have multiple where lines, I get an "invalid column name" message for my second where clause, but only when I'm using cfqueryparam
For example on the following I get "Invalid column name 'position_id'"
SELECT department_staff_tbl.*,
( SELECT max(bookmark_id)
FROM bookmarked_items_tbl
WHERE item_id = department_staff_tbl.staff_id
) AS bookmark_id
FROM department_staff_tbl
WHERE department_id = <cfqueryparam value="#arguments.deptid#" cfsqltype="cf_sql_integer">
AND position_id = <cfqueryparam value="#arguments.posid#" cfsqltype="cf_sql_integer">
AND staff_id = <cfqueryparam value="#arguments.staffid#" cfsqltype="cf_sql_integer">
If I change the order of my where clause so staff_id is first, then it tells me "department_id" is an invalid column.
If I only have one where clause, it works. (i.e. WHERE position_id = <cfqueryparam value="#arguments.posid#" cfsqltype="cf_sql_integer">).
If I remove the where clause from my subquery (WHERE item_id = department_staff_tbl.staff_id) it works.
It also works if I remove the cfqueryparam from my where clause so that my query looks like this:
SELECT department_staff_tbl.*,
( SELECT max(bookmark_id)
FROM bookmarked_items_tbl
WHERE item_id = department_staff_tbl.staff_id
) AS bookmark_id
FROM department_staff_tbl
WHERE department_id = #arguments.deptid#
AND position_id = #arguments.posid#
AND staff_id = #arguments.staffid#
Any thoughts?I see two tables. So can the server. So, use qualified column-names.
SELECT department_staff_tbl.*,
( SELECT max(bookmarked_items_tbl.bookmark_id)
FROM bookmarked_items_tbl
WHERE bookmarked_items_tbl.item_id = department_staff_tbl.staff_id
) AS bookmark_id
FROM department_staff_tbl
WHERE department_staff_tbl.department_id = <cfqueryparam value="#arguments.deptid#" cfsqltype="cf_sql_integer">
AND department_staff_tbl.position_id = <cfqueryparam value="#arguments.posid#" cfsqltype="cf_sql_integer">
AND department_staff_tbl.staff_id = <cfqueryparam value="#arguments.staffid#" cfsqltype="cf_sql_integer"> -
How do you use 3 Where Clauses in a query
Hi, i am trying to figure out how to use 3 Where Clauses in a Query where 2 of the Where Clauses uses a Sub query.
Display the OrderID of all orders that where placed after all orders placed by “Bottom-Dollar Markets”.
Order the result by OrderID in ascending order.
First WHERE clause checks for OrderDate and uses a sub query with ALL keyword.
Second WHERE clause use equals and sub query.
Third WHERE clause uses equal and company name.
This is what i have so far but i am pretty confused on how to do this.
My Code for NorthWind:
Select OrderID
From Orders o
Where o.OrderID IN (Select OrderDate From Orders Where Orders.OrderID > ALL
(Select CompanyName From Customers Where CompanyName = 'Bottom-Dollar Markets'));
The book shows how to use the ALL Keyword but not in a Sub query with Multiple Where Clauses.
Select VenderName, InvoiceNumber, InvoiceTotal
FROM Invoices JOIN Vendors ON Invoices.VendorID = Vendors.VendorID
WHERE InvoiceTotal > ALL (Select InvoiceTotal From Invoices Where VendorID = 34)
ORDER BY VendorName;>Where Orders.OrderDate
> ALL (Select
CompanyName
The comparison operator (>) requires compatible data types.
DATETIME is not compatible with VARCHAR string for comparison.
Here is your homework:
SELECT orderid
FROM orders o
WHERE o.orderdate > ALL (SELECT orderdate
FROM orders
WHERE shipvia = (SELECT Max(shipvia)
FROM orders o
INNER JOIN customers c
ON c.customerid =
o.customerid
WHERE
c.companyname = 'Bottom-Dollar Markets'));
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014 -
How can I pass multiple condition in where clause with the join table?
Hi:
I need to collect several inputs at run time, and query the record according to the input.
How can I pass multiple conditions in where clause with the join table?
Thanks in advance for any help.
Regards,
TDIf you are using SQL-Plus or Reports you can use lexical parameters like:
SELECT * FROM emp &condition;
When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
SELECT &columns FROM &tables &condition;
But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
Best of luck! -
Using multiple values in a where clause, for values only known at runtime
Dear all
I am creating a PL/SQL program which returns multiple rows of data but only where it meets a set id values that a user has previously chosen. The id values are stored in an associative array and are chosen by a user in the preceding procedure at run time.
I know all the table and column names in advance. The only things I don't know are the exact number of ids selected from the id column and what their values will be. This will only be known at runtime. When the procedure is run by the user it prints multiple rows of data to a web browser.
I have been reading the following posting, which I understand to a large extent, Query for multiple value search But I cannot seem to figure out how I would apply it to my work as I am dealing with multiple rows and a cursor.
The code as I have currently written it is wrong because I get an error not found message in my web browser. I think the var_user_chosen_map_list_ids in the for cursor loop could be the problem. I am using the variable_user_chosen_map_list_ids to store all the id values from my associatative array as a string. Which I modified from the code that vidyadhars posted in the other thread.
Should I be creating a OPEN FOR ref cursor and if so where would I put my associative array into it? At the moment I take the value, turning it into a string and IN part in the WHERE clause holds the string, allowing the WHERE clause to read all the values from it. I would expect the where clause to read everything in the string as 1 complete string of VARCHAR2 data but this would not be the case if this part of the code at least was correct. The code is as follows:
--Global variable section contains:
var_user_chosen_map_list_ids VARCHAR2(32767);
PROCEDURE PROCMAPSEARCH (par_user_chosen_map_list_ids PKG_ARR_MAPS.ARR_MAP_LIST)
IS
CURSOR cur_map_search (par_user_chosen_map_list_ids IN NUMBER)
IS
SELECT MI.map_date
MT.map_title,
FROM map_info MI,
map_title MT,
WHERE MI.map_title_id = MT.map_title_id
AND MI.map_publication_id IN
(var_user_chosen_map_list_ids);
var_map_list_to_compare VARCHAR2(32767) := '';
var_exe_imm_map VARCHAR2(32767);
BEGIN
FOR rec_user_chosen_map_list_ids IN 1 .. par_user_chosen_map_list_ids.count
LOOP
var_user_chosen_map_list_ids := var_user_chosen_map_list_ids ||
'''' ||
par_user_chosen_map_list_ids(rec_user_chosen_map_list_ids) ||
END LOOP;
var_user_chosen_map_list_ids := substr(var_user_chosen_map_list_ids,
1,
length(var_user_chosen_map_list_ids)-1);
var_exe_imm_map := 'FOR rec_search_entered_details IN cur_map_search
LOOP
htp.print('Map date: ' || cur_map_search.map_date || ' Map title: ' || cur_map_search.map_title)
END LOOP;';
END PROCMAPSEARCH;EXECUTE IMMEDIATE var_exe_imm_map;
I would be grateful of any comments or advice.
Kind regards
TimI would like to thank everyone for their kind help.
I have now successfully converted my code for use with dynamic SQL. Part of my problem was getting the concept confused a little, especially as I could get everything work in a static cursor, including variables, as long as they did not contain multiple values. I have learnt that dynamic sql runs the complete select statement at runtime. However even with this I was getting concepts confused. For example I was including variables and the terminator; inside my select string, where as these should be outside it. For example the following is wrong:
TABLE (sys.dbms_debug_vc2coll(par_user_chosen_map_list_ids))....
AND MI.map_publication_id = column_value;';Where as the following is correct:
TABLE (sys.dbms_debug_vc2coll('||par_user_chosen_map_list_ids||'))....
AND MI.map_publication_id = column_value';PL/SQL is inserting the values and then running the select statement, as opposed to running the select statement with the variables and then accessing the values stored in those variables. Once I resolved that it worked. My revised code is as follows:
--Global variable section contains:
var_user_chosen_map_list_ids VARCHAR2(32767);
var_details VARCHAR(32767);
PROCEDURE PROCMAPSEARCH (par_user_chosen_map_list_ids PKG_ARR_MAPS.ARR_MAP_LIST)
IS
BEGIN
FOR rec_user_chosen_map_list_ids IN 1 .. par_user_chosen_map_list_ids.count
LOOP
var_user_chosen_map_list_ids := var_user_chosen_map_list_ids ||
'''' ||
par_user_chosen_map_list_ids(rec_user_chosen_map_list_ids) ||
END LOOP;
var_user_chosen_map_list_ids := substr(var_user_chosen_map_list_ids,
1,
length(var_user_chosen_map_list_ids)-1);
var_details := FUNCMAPDATAFIND (var_user_chosen_map_list_ids);
htp.print(var_details);
END PROCMAPSEARCH;
FUNCTION FUNCMAPDETAILS (par_user_chosen_map_list_ids IN VARCHAR2(32767)
RETURN VARCHAR2
AS
TYPE cur_type_map_search IS REF CURSOR;
cur_map_search cur_type_map_search;
var_map_date NUMBER(4);
var_map_title VARCHAR2(32767);
begin:
OPEN cur_map_search FOR
'SELECT MI.map_date,
MT.map_title
FROM map_info MI,
map_title MT,
TABLE (sys.dbms_debug_vc2coll(' || par_user_chosen_map_list_ids || '))
WHERE MI.map_title_id = MT.map_title_id
AND MI.map_publication_id = column_value';
LOOP
FETCH cur_map_compare INTO
var_map_date,
var_map_title;
var_details := var_details || 'Map date: '||
var_map_date ||
'Map title: ' ||
var_map_title;
EXIT WHEN cur_map_compare%NOTFOUND;
END LOOP;
RETURN var_details;
END FUNCMAPDETAILS;Kind regards
Tim -
Select multiple value in a where clause
hello,
im using developer 2000.
suppose I have several values in a data grid. I want to use all of them in a where clause using IN operator or something. anybody knows how to do that. what I do is always insert all values in the grid into a temporary table and use that table in the where clause. is there any other easy, effective way of doing that?
select *
from table1
where category in (-- I want to select multiple values form a data grid here--)
thanks in advance.
bonny.Hello Bonny,
You might consider the use of PL/SQL Collection Types
The first step in the process is to create a type and a table of that type.
CREATE OR REPLACE TYPE DateType IS OBJECT ( Arg1 DATE );
CREATE OR REPLACE TYPE TableList IS TABLE OF DateType;
DECLARE
list1 tablelist;
BEGIN
SELECT datetype (arg1)
BULK COLLECT INTO list1
FROM table1;
FOR c1 IN (SELECT arg1
FROM TABLE (CAST (list1 AS tablelist)))
LOOP
---- Your code -----;
END LOOP;
END;
For further insight please refer: http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/05_colls.htm
Regards. -
Using multiple dates in WHERE clause
I have a multiple select box in a form. I am trying to select
records in SQL using the list that this form field produces. They
are dateTime values. How do I use this list in the WHERE clause of
my select statement?Man, I really hate posting anywhere near Dan - I've been
watching his mastery for years. (Talk about the big leagues) But
here goes anyway...
I've gotten my little behind kicked by more than a view date
issues, and I have basically gotten away from exact matches (unless
you really need them).
I'd probably do something like this:
SELECT field1,field2...
WHERE datetime_column_in_db > (OR LTE,OR GT/LT)
'#datetimeformatyoulike(form.datetimevalue1)#
Basically, finding records in RELATION to the form's datetime
value has always been much easier for me.
And God (and Dan) have mercy on my soul... -
The issue with using the multiple columns sub-query in WHERE clause
Hi All,
my database version is 10.2.
the problem i am trying to deal with is that when I use multiple column sub-query in the WHERE clause of the SELECT statement, the actual row number returned from the sub-query is different from the whole statement.
And what I found is that, whenever there is NULL in any of those columns returned from the SUB-QUERY, the outer query will just return NULL for that whole row.
Here is an example:
select empno, ename, job, mgr, hiredate, sal, deptno from EMP
intersect
select empno, ename, job, mgr, hiredate, sal, deptno from t;
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7839 KING PRESIDENT NULL 17-NOV-81 5000 10
7934 MILLER CLERK 7782 23-JAN-82 1300 10
select * from EMP where (EMPNO, ENAME, job, MGR, HIREDATE, SAL, DEPTNO) in (
select empno, ename, job, mgr, hiredate, sal, deptno from EMP
intersect
select empno, ename, job, mgr, hiredate, sal, deptno from t);
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7934 MILLER CLERK 7782 23-JAN-82 1300 10 If I specifically deal with the NULL situations for the columns which might return NULL, I can get the result right.
select * from EMP where (EMPNO, ENAME, job, NVL(MGR,-1), HIREDATE, SAL, DEPTNO) in (
select empno, ename, job, nvl(mgr,-1), hiredate, sal, deptno from EMP
intersect
select empno, ename, job, nvl(mgr,-1), hiredate, sal, deptno from t);
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7839 KING PRESIDENT null 17-NOV-81 5000 10
7934 MILLER CLERK 7782 23-JAN-82 1300 10 the problem is that, I feel this is a very lame way of handling it.
So, I wonder or am asking if there is any better or standard way to do it?
any help would be highly appreciated.
ThanksHi,
As you discovered, INTERSECT treats NULL as a value, but IN does not.
What you did with NVL is one way to handle the situation. If there was a chance that any of the columns could be NULL, then you might prefer something like this:
select *
from EMP
where ( EMPNO || '~' ||
ENAME || '~' ||
job || '~' ||
MGR || '~' ||
TO_CHAR (HIREDATE, 'DD-MON-YYYY HH24:MI:SS')
|| '~' ||
SAL || '~' ||
DEPTNO
) in (
select EMPNO || '~' ||
ENAME || '~' ||
job || '~' ||
MGR || '~' ||
TO_CHAR (HIREDATE, 'DD-MON-YYYY HH24:MI:SS')
|| '~' ||
SAL || '~' ||
DEPTNO
from emp
intersect
select EMPNO || '~' ||
ENAME || '~' ||
job || '~' ||
MGR || '~' ||
TO_CHAR (HIREDATE, 'DD-MON-YYYY HH24:MI:SS')
|| '~' ||
SAL || '~' ||
DEPTNO
from t
);This assumes that you can identify some string (I used '~') that never occurs in the strings in these tables.
This is implicitly converting the NUMBERs. That's usually not a good thing to do. but explicitly converting them would make this even more tedious.
You should explicitly convert any DATEs to strings, however. Depending on your default format, and your data, you might get away with implicit conversions even for DATEs, but don't bet on it.
If you had to do this often, you might consider writing a user-defined function:
delimited_string (empno, ename, job, mgr, hiredate, sal, deptno) would return a string like
'7839~KING~PRESIDENT~~17-NOV-1981~5000~10'
This will make the coding easier, but beware: it will make the execution slower. -
Dynamic page with multiple select in where clause
Hi,
I have a dynamic page and in the where-clause, i have a bind variable. In a report i use for instance
and rtrim((to_char(date_time5,'DAY'))) IN :v_day
That works ok in a report. But it does not work in a dynamic page.
what code is needed to work with a multiple select box on the customize screen for a dynamic page?
Thanks.Hi.
I have a dynamic page, with a bind variable :v_day. On the customization screen the user can select one or more days of the week, or all days. I use this also in a report and then it works ok. In the where clause i use:
and rtrim((to_char(date_time,'DAY'))) IN :v_day
Date_time is a tablecolumn (date).
When i add this line in the select script from the dynamic page, i get error:
: ORA-06550: line 1, column 2443:
PLS-00103: Encountered the symbol "" when expecting one of the following:
The symbol "(" was substituted for "" to continue.
ORA-06550: line 1, column 2606:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
. ( ) , * @ % & - + / at mod rem <an exponent (**)> and or ||
The symbol ")" was substituted for ";" to continue.
ORA-06550: line 1, column 3236:
PLS-00103: Encountered the symbol "" when expecting one of the following:
The symbol (WWV-11230)
Critical Error in wwerr_api_error.get_errors! SQL Error Message: ORA-06502: PL/SQL: numeric or value error: character string buffer too small (WWV-)
Thanks. -
Dynamic where clause for MULTIPLE values
In the following of dynamic where clause?
i have some somewhat different problem.
Is a dynamic where clause for multiple values possible?
If the inputvariable varCode1,varCode2,varCode3,varCode4 are 0 then show all id's otherwise filter the resultset on var1 and/or var2,and/or var3,and/or var4.
Example table:
create table t
(d int,var int);
insert into t values (1 ,1 );
insert into t values (2 ,1 );
insert into t values (3 ,2 );
insert into t values (4 ,3 );
insert into t values (5 ,4 );
insert into t values (6 ,4 );
insert into t values (7 ,4 );
insert into t values (8 ,4 );
insert into t values (9 ,5 );
insert into t values (10, 6);
insert into t values (11, 6);
So what i want to change the where clause upon the value of the varCodes. If var1 and var are not 0 a "AND" should be used otherwise an "OR"
select id
from tst
where var = DECODE( :varCode1, 0, var, :varCode1)
or/and(?) DECODE( :varCode2, 0, var, :varCode2)
or DECODE( :varCode3, 0, var, :varCode3)
or DECODE( :varCode4, 0, var, :varCode4)Please turn off your Caps Lock
and try this link
Dynamic WHERE clause -
Passing Multiple Parameters to a Where clause
Dear All,
Using Crystal 11.5 on XP workstations, communicating with a SQL database.
I want to allow users to input two or three or four Meeting codes -- text fields about 10 characters -- into a Crystal multiple parameter field. Then I want to use those names to access data for each meeting, grouping on the meeting . . .
WHERE meeting.name = 'MeetingCode1' or meeting.name = 'MeetingCode2 or meeting.name = 'MeetingCode3'
I've tried just using "IN" with the parameter and that won't work for this -- though it seems to get data for cvross tabs which is puzzling. I've tried using the JOIN function to parse out the data and build the WHERE clause and have been unsuccessful (but if you tell me that should work, I can go at it again that way -- all kinds of issues there comparing it to Crystal's SQL view.
Any thoughts about how to tackle this would be greatly appreciated.
Sincerely,
Ridge (in New Joisey)I just tested this again -- going very slowly and very carefully -- and it seems to be working setting the
{ table.field} IN
for both numeric and string values.
Sorry for wasting bandwidth.
R -
How to use multiple search conditions in the where clause
Hi,
Below is my query
/****** Script for SelectTopNRows command from SSMS ******/
SELECT distinct
ctacct,sum(GLMN02)
FROM [ODS].[Staging].[tODS_INF_GLPCT]
inner join
[ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
where
CTACCT like '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%'
This one gives me the exact result i want, now if i add one more to my where clause like this
/****** Script for SelectTopNRows command from SSMS ******/
SELECT distinct
ctacct,sum(GLMN02)
--,ctdesc,CTPAGE
--SUM(GLMN02)
FROM [ODS].[Staging].[tODS_INF_GLPCT]
inner join
[ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
where
CTACCT like'[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%' or
CTACCT like '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
This query doesnt give me the exact values instead it gives me all the weird values.Can someone please help me with how to work on this where clause?
ThanksHi Patrick,
This is what i ve tried earlier and it isnt working .If i use the first query
/****** Script for SelectTopNRows command from SSMS ******/
SELECT distinct
ctdesc,SUM(GLMN02)
--,ctdesc,CTPAGE
--SUM(GLMN02)
FROM [ODS].[Staging].[tODS_INF_GLPCT]
inner join
[ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
where
CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%'
--OR
--CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
and GLYEAR = 2014
and CTDESC = 'Sales'
group by ctdesc
The result set is
Sales
-182273.96
And if i use the second query
SELECT distinct
ctdesc,SUM(GLMN02)
--,ctdesc,CTPAGE
--SUM(GLMN02)
FROM [ODS].[Staging].[tODS_INF_GLPCT]
inner join
[ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
where
CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%'
OR
CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
and GLYEAR = 2014
and CTDESC = 'Sales'
group by ctdesc
The result set i get is
Sales
-1455441.08
And i verified that CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
this second line of where clause has not desc as Sales.
I am not sure whats causing the difference in the values.
Can you please help me with this?
Thanks -
How to create VO with multiple dynamic where clauses on select with UNION?
I am trying to implement the View Object for the UNION query that looks like this:
select a,b,c...
from t1,t2,...
where dynamic_where_clause1
union all
select a,b,c,...
from t11,t12, ...
where dynamic_where_clause2
There are up to 60 input parameters that are used to generate dynamic where clauses. They are actually created by calling PL SQL function.
So far, I was not able to assign both where clauses to the view object. Is there a workable solution for this problem, besides resorting to programmatic View Object?
I understand that recommended way with UNIONs is to wrap both queries into a parent select:
select * from (
select a,b,c...
from t1,t2,...
where ... -- table relationship joints
union all
select a,b,c,...
from t11,t12, ...
where ... -- table relationship joints
) QRSLT
where dynamic_where_clause
Unfortunately this approach doesn't work here, since individual selects are producing unmanageable amount of data and resulting query takes forever to complete.I afraid I would not have any real benefits from using VO if I replace the entire query with every request. Actually, the performance may suffer.
I solved the problem by creating a POJO Data Control and invoking the custom select query from java. Not sure if it is the best approach to the problem, but implementation time is limited and it works.
Actually, this is not the first time I see the need to implement VO with complicated SQL like select with unions and dynamic pieces. It would be nice to find a solution and not resort to workarounds.
Edited by: viksicom on Aug 2, 2012 8:48 AM -
Where Clause With Multiple Rows
I am tracking Objects called Incidents. Incidents can be made up of an undetermined number of questions and answers, such that my table structure to store these incidents looks as follows:
INCIDENT_ID QUESTION_ID ANSWER_ID
10001 49100 100 ("YES")
10001 49101 275 ("5 HOURS")
10002 49100 102 ("NO")
10002 49101 276 ("10 HOURS")I allow my users to enter complex queries, such as "give me all incidents where question 49100 equals YES AND question 49101 equals 5 or less, OR where 49100 equals NO and 49101 is greater than 5", etc...
My problem is how to handle these types of complex queries. Right now, I bring all of the rows into a Java object, and then I can analyze the results using Java (this works elegantly and allows me to have very complex formulas).
However, if I have to deal with millions of Incidents and Answers, bringing them all into Java seems to be very time consuming. I'd like to be able to handle everything in the database. Because I allow my users to enter the queries through a "query builder", I can't control how many conditions they might have. In other words, if I try to use inner queries in the WHERE clause, I may exceed limits.
It would be easiest if I could translate this vertical table into a temporary horizontal table, and then run my query on this horizontal table. My problem is that some of my questions have 1000s of answers (where they might be picking from a large select list), and therefore I can't do sums and counts on all the choices in separate columns. If I try a bit field for each column, once again I can run out of space because of the 1000s of possible answers.
Has anyone faced this issue before? What choices do I have to make this all work in the database without having to parse the results in Java?
MichaelI was under the impression that each medication uses a unique id itself (defined perhaps by the medical insurance industry) and that itemized lists contain that code. And thus the user can type in the code.
If so then one could handle the interface using both of the following methods.
- The user can type in the id (this is validated.)
- The user can push a button to bring up a dialog that provides the list and also provides an intelligent search option. (Or the id field can just be an aspect of the intelligent search.)
Even in a small doctor's office experienced users will probably know the common ids and it would be simpler for them to type that in. In a processing center this would be more important as the time to process each transaction directly impacts the bottom line. This becomes much more relevant when the users are paid bonuses based on how many transactions they process (and managers might get that as well.)
Maybe you are looking for
-
How do I add to the list of servers in 'Date & Time' System Preferences?
Earlier versions of the Mac OS (9 and below, I believe) allowed a user to add to the list of time servers in what was then the Date and Time Control Panel. Now, under OS X (Tiger), I am able to select from the three servers that Apple provides, but I
-
Problems syncing with iTunes 8
My iPhone used to be able to plug into iTunes and the normal occurrence of the 'sync in progress' screen would show up and continue syncing as normal. Ever since iTunes 8, I plug n my iPhone and the screen goes off and iTunes freezes without successf
-
IDoc to CRM - change pointers?
Hi, I'm currently involved in scenarios where I need to post various CRMXIF_* IDocs to CRM. What I'm wondering is, if I need to maintain change pointers in the IDocs - that is at header and item level maintain the fields OBJECT_TASK or TASK with prop
-
Dear all we are implementing sap ecc 6.0 and my previous project is SAP All in one ecc 5.0 where i have installed building blocks. After installing building blocks some Abap smart forms got updated then it became easy for our Abap consultant to mak
-
I just bought a iPod Nano for my wife. I have no luck with the FM radio. It seems to think I'm in Austrialia. Any ideas as to what to do?