Need help with querying pl/sql collections
hi all,
i have a requirement wherein i look thru a number of records and then updates. then i need to check if these records were successfully updated. i have the following code but it doesn't work on the part where i query the collection.
declare
type ap_invoices_all_tbl is table of ap_invoices_all%rowtype;
ap_invoices_all_rec ap_invoices_all_tbl;
cursor cai is
select *
from ap_invoices_all ai
where source = 'XXX';
begin
open cai;
fetch cai bulk collect into ap_invoices_all_rec;
for i in 1..ap_invoices_all_rec.count loop
begin
dbms_output.put_line('Invoice Status: ' || ap_invoices_pkg.get_approval_status( ap_invoices_all_rec(i).invoice_id, ap_invoices_all_rec(i).invoice_amount, ap_invoices_all_rec(i).payment_status_flag, ap_invoices_all_rec(i).invoice_type_lookup_code));
exception
when no_data_found then
null;
end;
end loop;
for j in ( select * from ap_invoices_all ai
where invoice_id in ( select invoice_id
from ap_invoices_all_rec ))
loop
dbms_output.put_line('Invoice Number: ' || j.invoice_num);
end loop;
end;i do understand that i cannot use select statement directly on a collection but i just wanted to show what i'm trying to achieve.
any suggestions on what i should do?
thanks
allen
You can not use locally defined collection(pl/sql) in SELECT statement directly, instead use Objects defined in schema.
For example:
SQL> CREATE OR REPLACE TYPE emp_rec IS OBJECT (
2 v_sal NUMBER(7,2),
3 v_name VARCHAR2(35),
4 v_empno NUMBER(4),
5 v_deptno NUMBER(2)
6 )
7 ;
8 /
Type created.
SQL> CREATE OR REPLACE TYPE emp_tab IS TABLE OF emp_rec;
2 /
Type created.
SQL> CREATE OR REPLACE TYPE dept_rec IS OBJECT (
2 v_deptno NUMBER,
3 v_dname VARCHAR2(50)
4 )
5 ;
6 /
Type created.
SQL> CREATE OR REPLACE TYPE dept_tab IS TABLE OF dept_rec;
2 /
Type created.
SQL> CREATE OR REPLACE TYPE emp_dept_rec IS
2 OBJECT (
3 v_sal NUMBER,
4 v_name VARCHAR2(35),
5 v_deptname VARCHAR2(30)
6 );
7 /
Type created.
SQL> CREATE OR REPLACE TYPE emp_dept_tab_type IS TABLE OF emp_dept_rec;
2 /
Type created.
SQL> set serverout on
SQL> DECLARE
2 l_emp_dept_tab emp_dept_tab_type; --emp_dept_tab_type declared in database
3 l_emp_tab emp_tab; --emp_tab declared in database
4 l_dept_tab dept_tab; --dept_tab declared in database
5
6 CURSOR e1 IS
7 SELECT emp_rec(sal, ename, empno, deptno) FROM emp; --Note the type casting here
8
9 CURSOR d1 IS
10 SELECT dept_rec(deptno, dname) FROM dept; --Note the type casting here
11 BEGIN
12 OPEN e1;
13
14 FETCH e1 BULK COLLECT
15 INTO l_emp_tab;
16
17 OPEN d1;
18
19 FETCH d1 BULK COLLECT
20 INTO l_dept_tab;
21
22 SELECT CAST(MULTISET (SELECT em.v_sal, em.v_name, dep.v_dname
23 FROM TABLE(l_emp_tab) em, TABLE(l_dept_tab) dep
24 WHERE em.v_deptno = dep.v_deptno) AS emp_dept_tab_type)
25 INTO l_emp_dept_tab
26 FROM DUAL;
27 FOR i IN 1 .. l_emp_dept_tab.COUNT LOOP
28 dbms_output.put_line(l_emp_dept_tab(i)
29 .v_sal || '--' || l_emp_dept_tab(i)
30 .v_name || '--' || l_emp_dept_tab(i).v_deptname);
31 END LOOP;
32
33 END;
34 /
1300--MILLER--ACCOUNTING
5000--KING--ACCOUNTING
2450--CLARK--ACCOUNTING
3000--FORD--RESEARCH
1100--ADAMS--RESEARCH
3000--SCOTT--RESEARCH
2975--JONES--RESEARCH
800--SMITH--RESEARCH
950--JAMES--SALES
1500--TURNER--SALES
2850--BLAKE--SALES
1250--MARTIN--SALES
1250--WARD--SALES
1600--ALLEN--SALES
PL/SQL procedure successfully completed.
SQL>
Similar Messages
-
Need help with query that can look data back please help.
hi guys i have a table like such
CREATE TABLE "FGL"
"FGL_GRNT_CODE" VARCHAR2(60),
"FGL_FUND_CODE" VARCHAR2(60),
"FGL_ACCT_CODE" VARCHAR2(60),
"FGL_ORGN_CODE" VARCHAR2(60),
"FGL_PROG_CODE" VARCHAR2(60),
"FGL_GRNT_YEAR" VARCHAR2(60),
"FGL_PERIOD" VARCHAR2(60),
"FGL_BUDGET" VARCHAR2(60)
)and i have a data like such
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','1','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','2','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7470','4730','02','10','2','200');I bascially need to get the total of the budget column. however its not as simple as it sound(well atleast not for me.) the totals carry over to the new period. youll noticed the you have a period column. basically what im saying is that
fgl_grant_year 10 period 1 = for account 7600 its $100 and $100 for period 2 you see 100 dollars again this is not to be added this is the carried over balance. which remains $100.
so im trying to write a query that basically does the following.
im given a period for the sake of this example lets say period 1 i get nothing else. I have to find the greates grant year grab the amount for period 14(which is the total from the previous year) and add it to the amount of the current period. in this case period 1 grnt_year 11
so the expected outcome should be $700
240055 240055 7240 4730 02 10 14 200
240055 240055 7600 4730 02 10 14 100
240055 240055 7600 4730 02 11 1 400keep in mind that im not given a year just a period.
any help that you guys can offer would be immensely appreciated. I have been trying to get this to work for over 3 days now.
finally broke down and put together this post
Edited by: mlov83 on Sep 14, 2011 8:48 PMFrank
wondering if you can help me modify this sql statement that you provided me with .
table values have been modified a bit.
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','00','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7200','4730','02','10','1','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7600','4730','02','10','1','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','2','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','11','2','600');i need to take one more thing into consideration. if the greatest year has a value on period 00 i need to ignore the period 14 and the current period total would be
the current period +(current period - greatest year 00)
hope that makes sense so in other words with the new data above. if i was querying period two of grant year 11. i would end up with $800
because the greatest year is 11 it contains a period 0 with amount of $400 so my total should be
period 2 amount $ 600
period 0 amount $ 400 - period 2 amount of $600 = 200
600+200 = $800
if i query period 1 of grant 360055 i would just end up with 800 of grnt year 10.
i have tried to modify that query you supplied to me with no luck. I have tried for several day but im embarrased to say i just can get it to do what im trying to do .
can you please help me out.
Miguel -
Need help with query joining several tables into a single return line
what i have:
tableA:
puid, task
id0, task0
id1, task1
id2, task2
tableB:
puid, seq, state
id0, 0, foo
id0, 1, bar
id0, 2, me
id1, 0, foo
id2, 0, foo
id2, 1, bar
tableC:
puid, seq, date
id0, 0, 12/21
id0, 1, 12/22
id0, 2, 12/22
id1, 0, 12/23
id2, 0, 12/22
id2, 1, 12/23
what i'd like to return:
id0, task0, 12/21, 12/22, 12/22
id1, task1, 12/23, N/A, N/A
id2, task2, 12/22, 12/23, N/A
N/A doesn't mean return the string "N/A"... it just means there was no value, so we don't need anything in this column (null?)
i can get output like below through several joins, however i was hoping to condense each "id" into a single line...
id0, task0, 12/21
id0, task0, 12/22
id0, task0, 12/23
id1, task1, 12/23
is this possible fairly easily?
Edited by: user9979830 on Mar 29, 2011 10:53 AM
Edited by: user9979830 on Mar 29, 2011 10:58 AMHi,
Welcome to the forum!
user9979830 wrote:
what i have:...Thanks for posting that so clearly!
Whenever you have a question, it's even better if you post CREATE TABLE and INSERT statements for your sample data, like this:
CREATE TABLE tablea
( puid VARCHAR2 (5)
, task VARCHAR2 (5)
INSERT INTO tablea (puid, task) VALUES ('id0', 'task0');
INSERT INTO tablea (puid, task) VALUES ('id1', 'task1');
INSERT INTO tablea (puid, task) VALUES ('id2', 'task2');
CREATE TABLE tablec
( puid VARCHAR2 (5)
, seq NUMBER (3)
, dt DATE -- DATE is not a good column name
INSERT INTO tablec (puid, seq, dt) VALUES ('id0', 0, DATE '2010-12-21');
INSERT INTO tablec (puid, seq, dt) VALUES ('id0', 1, DATE '2010-12-22');
INSERT INTO tablec (puid, seq, dt) VALUES ('id0', 2, DATE '2010-12-22');
INSERT INTO tablec (puid, seq, dt) VALUES ('id1', 0, DATE '2010-12-23');
INSERT INTO tablec (puid, seq, dt) VALUES ('id2', 0, DATE '2010-12-22');
INSERT INTO tablec (puid, seq, dt) VALUES ('id2', 1, DATE '2010-12-23');This way, people can re-create the problem and test their ideas.
It doesn't look like tableb plays any role in this problem, so I didn't post it.
Explain how you get the results from that data. For example, why do you want this row in the results:
PUID TASK DT1 DT2 DT3
id0 task0 12/21/2010 12/22/2010 12/22/2010rather than, say
PUID TASK DT1 DT2 DT3
id0 task0 12/22/2010 12/21/2010 12/22/2010? Does 12/21 have to go in the first column because it is the earliest date, or is it because 12/21 is related to the lowest seq value? Or do you even care about the order, just as long as all 3 dates are shown?
Always say what version of Oracle you're uisng. The query below will work in Oracle 9 (and up), but starting in Oracle 11, the SELECT ... PIVOT feature could help you.
i can get output like below through several joins, however i was hoping to condense each "id" into a single line... Condensing the output, so that there's only one line for each puid, sounds like a job for "GROUP BY puid":
WITH got_r_num AS
SELECT puid
, dt
, ROW_NUMBER () OVER ( PARTITION BY puid
ORDER BY seq -- and/or dt
) AS r_num
FROM tablec
-- WHERE ... -- If you need any filtering, put it here
SELECT a.puid
, a.task
, MIN (CASE WHEN r.r_num = 1 THEN r.dt END) AS dt1
, MIN (CASE WHEN r.r_num = 2 THEN r.dt END) AS dt2
, MIN (CASE WHEN r.r_num = 3 THEN r.dt END) AS dt3
, MIN (CASE WHEN r.r_num = 4 THEN r.dt END) AS dt4
FROM tablea a
JOIN got_r_num r ON a.puid = r.puid
GROUP BY a.puid
, a.task
ORDER BY a.puid
;I'm guessing that you want the dates arranged by seq; that is, for each puid, the date related to the lowest seq comes first, regardless of whther that date is the earliest date for that puid or not. If that's not what you need, then change the analytic ORDER BY clause.
This does not assume that the seq values are always consecutive integers (0, 1, 2, ...) for each puid. You can skip, or even duplicate values. However, if the values are always consecutive integers, starting from 0, then you could simplify this. You won't need a sub-query at all; just use seq instead of r_num in the main query.
Here's the output I got from the query above:
PUID TASK DT1 DT2 DT3 DT4
id0 task0 12/21/2010 12/22/2010 12/22/2010
id1 task1 12/23/2010
id2 task2 12/22/2010 12/23/2010As posted, the query will display the first 4 dts for each puid.
If there are fewer than 4 dts for a puid, the query will still work. It will leave some columns NULL at the end.
If there are more than 4 dts for a puid, the query will still work. It will display the first 4, and ignore the others.
There's nothing special about the number 4; you could make it 3, or 5, or 35, but whatever number you choose, you have to hard-code that many columns into the query, and always get that many columns of output.
For various ways to deal with a variable number of pivoted coolumns, see the following thread:
PL/SQL
This question actually doesn't have anything to do with SQL*Plus; it's strictly a SQL question, and SQL questions are best posted on the "SQL and PL/SQL" forum:
PL/SQL
If you're not sure whether a question is more of a SQL question or a SQL*Plus question, then post it on the SQL forum. Many more people pay attention to that forum than to this one. -
Need Help with Formula using SQL maybe
I need help! I work with Crystal reports XI and usually manage just fine with the Formula editor but his one I think will require some SQL and I am not good at that.
We are running SQL 2000 I think (Enterprise Manager 8.0) Our sales people schedule activities and enter notes for customer accounts. Each is stored in a separate table. I need to find activities that are scheduled 240 days into the future and show the most recent note that goes with the account for which that activity is scheduled.
The two tables, Activities and History, share the an accountID field in common that links them to the correct customer account. I want to look at dates in the Startdate.Activities field more than 240 days in the future and show the most recent note from the History table where the accountid's match. I figure my query will contain a join on AccountID.Activities and AccountID.History used with Max(completedate.History) but I do not understand how to word it.
I would like to perform all this in crystal if possible. I humbly request your help.
MemberyYou SQL would look something like this...
SELECT
a.AccountID,
a.BlahBlahBlah, -- Any other fields you want from the Activities table
h.LastComment
FROM Activities AS a
LEFT OUTER JOIN History AS h ON a.AccountID = h.AccountID
WHERE (a.ActivityDate BETWEEN GetDate() AND DateAdd(dd, 240, GetDate()))
AND h.HistoryID IN (
SELECT MAX(HistoryID)
FROM History
GROUP BY AccountID)
This method assumes that the History table has a HistoryID that increments up automatically each time a new comment is added... So a comment made today would always have a higher HistoryID that one made yesterday.
If I'm wrong and there is no HistoryID or the HistoryID doesn't increment in a chronological fashion, it can still be done but the code is a bit more complex.
HTH,
Jason -
hi all, forgot i had a user name and password and haven't needed help for quite a bit since i didn't do sql for a while but now i'm back at reporting again...
Here is a sample table as i remember it:
Item Date Time Time Frame Duration Duration Frame
A 20100926 0 5 500 10
A 20100926 600 10 500 30
A 20100926 1500 12 100 30
B 20100926 1800 28 200 40
B 20100926 2200 6 150 70
B 20100926 2600 15 600 60
B 20100926 3600 30 200 70
Results Set (expected):
Item Date Time Total Duration
A 20100926 0 1600:20 --basically max (time+duration) - min(time+duration)
B 20100926 1800 2000:00
Sorry, but. I didnt put my sql statement as I wasn't planning on posting and left it at work, but, i've been looking on internet and people say to use min/max function and i've attenpted it with it works with just this table (without grouping). But as soon as i group it the values seem to mess up.
Last i remembered it gave me:
Item Date Time Total Duration
A 20100926 0 1600:30 --basically max(time+duration) - min(time+duration)
B 20100926 1800 2000:70
I think it's looking at max duration which is 30&70 and hence it retrurns those values in the result set. Is it because of the max function hence it's returning this value? any help is appreciated. thanks
Edited by: stanleyho on Sep 30, 2010 4:44 PMOkay, here we go again, repost, hopefully okay this time:
Hi Madhu, okay, just got to work: I am using TOAD and working in Oracle 10g. Here is my table structure and the query i use to try and get what I am looking for:
There is one extra table but that is only used to link these two tables listed below so i didn't bother posting it.
TABLE: TX_RECON_INSTANCE_VIEW
ColumnName ColID DataType Null
CHANNEL_CODE 3 VARCHAR2 (4 Char) N
DURATION 8 NUMBER (10) N
DURATION_FRAME 9 NUMBER (2) N
REAL_TIME 6 NUMBER (10) N
REAL_TIME_FRAME 7 NUMBER (2) N
ITEM_ID 4 NUMBER Y
TX_DATE 2 CHAR (8 Byte) N
TX_ID 1 NUMBER (9) N
TX_TYPE 13 VARCHAR2 (4 Char) N
TABLE: TX_SCHEDULE
ColumnName ColID PK Null DataType
TX_TYPE 22 N VARCHAR2 (4 Char)
TX_ID 1 1 N NUMBER (9)
TX_DATE 2 N CHAR (8 Byte)
SCHEDULE_TIME_FRAME 9 N NUMBER (2)
SCHEDULE_TIME 8 N NUMBER (10)
REAL_TIME 10 N NUMBER (10)
DURATION_FRAME 13 N NUMBER (2)
DURATION 12 N NUMBER (10)________________________________________
And the data and results:
TX_ID TX_DATE REAL_TIME REAL_TIME_FRAME DURATION DURATION_FRAME ITEM_ID AS RUN TIME AS RUN DURATION SCHEDULED TIME SCHEDULED DURATION SCHEDULE_TIME SCHEDULE_TIME_FRAME DURATION_1 DURATION_FRAME_1
1651000 20100710 0 0 545 20 1234 00:00:00:00 00:09:05:20 00:00:00:00 00:09:05:20 0 0 545 20
1752223 20100710 667 12 281 7 1234 00:11:07:12 00:04:41:07 00:11:07:10 00:04:41:07 667 10 281 7
1846501 20100710 1071 13 335 9 1234 00:17:51:13 00:05:35:09 00:17:50:09 00:05:35:09 1070 9 335 9
2001102 20100710 1525 6 249 14 1234 00:25:25:06 00:04:09:14 00:25:22:08 00:04:09:14 1522 8 249 14
3246669 20100710 1800 0 586 2 1235 00:30:00:00 00:09:46:02 00:30:00:00 00:09:46:02 1800 0 586 2
4456822 20100710 2492 16 276 5 1235 00:41:32:16 00:04:36:05 00:41:32:16 00:04:36:05 2492 16 276 5
1253168 20100710 2890 15 222 17 1235 00:48:10:15 00:03:42:17 00:48:10:15 00:03:42:17 2890 15 222 17
1112456 20100710 3277 18 297 0 1235 00:54:37:18 00:04:57:00 00:54:35:10 00:04:57:00 3275 10 297 0
Grouped results set:
TX_DATE ITEM_ID AS RUN TIME AS RUN DURATION SCHEDULED TIME SCHEDULED DURATION
20100710 1234 00:00:00:00 00:29:34:20 00:00:00:00 00:29:31:20
20100710 1235 00:30:00:00 00:29:34:17 00:30:00:00 00:29:32:17
--> SCHEDULED DURATION "00:29:31:20" is not correct as it should be (00:25:22:08+00:04:09:14)-(00:00:00:00)=00:29:31:22
--> see expected results below
Expected results:
TX_DATE ITEM_ID AS RUN TIME AS RUN DURATION SCHEDULED TIME SCHEDULED DURATION
20100710 1234 00:00:00:00 00:29:34:20 00:00:00:00 00:29:31:22
20100710 1235 00:30:00:00 00:29:34:18 00:30:00:00 00:29:34:10________________________________________
And the query I am using:
SELECT --TXR.TX_ID,
TXR.TX_DATE, TXR.ITEM_ID,
TO_CHAR(TRUNC((MIN(TXR.REAL_TIME) KEEP (DENSE_RANK FIRST ORDER BY TXR.REAL_TIME) )/3600),'FM00')||':'||TO_CHAR(TRUNC(MOD(MIN(TXR.REAL_TIME) KEEP (DENSE_RANK FIRST ORDER BY TXR.REAL_TIME) ,3600)/60),'FM00')||':'||TO_CHAR(MOD(MIN(TXR.REAL_TIME) KEEP (DENSE_RANK FIRST ORDER BY TXR.REAL_TIME) ,60),'FM00')||':'||TO_CHAR(MOD(MIN(TXR.REAL_TIME_FRAME) KEEP (DENSE_RANK FIRST ORDER BY TXR.REAL_TIME) ,60),'FM00') "AS RUN TIME",
to_char(trunc((MAX(TXR.REAL_TIME+TXR.DURATION)-MIN(TXR.REAL_TIME))/3600),'FM00')||':'||to_char(trunc(mod(MAX(TXR.REAL_TIME+TXR.DURATION)-MIN(TXR.REAL_TIME),3600)/60),'FM00')||':'||to_char(mod(MAX(TXR.REAL_TIME+TXR.DURATION)-MIN(TXR.REAL_TIME),60),'FM00')||':'||to_char(mod(MAX(TXR.REAL_TIME_FRAME+TXR.DURATION_FRAME)-MIN(TXR.REAL_TIME),60),'FM00') "AS RUN DURATION",
TO_CHAR(TRUNC((MIN(TXS.SCHEDULE_TIME) KEEP (DENSE_RANK FIRST ORDER BY TXR.REAL_TIME) )/3600),'FM00')||':'||TO_CHAR(TRUNC(MOD(MIN(TXS.SCHEDULE_TIME) KEEP (DENSE_RANK FIRST ORDER BY TXR.REAL_TIME) ,3600)/60),'FM00')||':'||TO_CHAR(MOD(MIN(TXS.SCHEDULE_TIME) KEEP (DENSE_RANK FIRST ORDER BY TXR.REAL_TIME) ,60),'FM00')||':'||TO_CHAR(MOD(MIN(TXS.SCHEDULE_TIME_FRAME) KEEP (DENSE_RANK FIRST ORDER BY TXR.REAL_TIME) ,60),'FM00') "SCHEDULED TIME",
to_char(trunc((MAX(TXS.SCHEDULE_TIME+TXS.DURATION)-MIN(TXS.SCHEDULE_TIME))/3600),'FM00')||':'||to_char(trunc(mod(MAX(TXS.SCHEDULE_TIME+TXS.DURATION)-MIN(TXS.SCHEDULE_TIME),3600)/60),'FM00')||':'||to_char(mod(MAX(TXS.SCHEDULE_TIME+TXS.DURATION)-MIN(TXS.SCHEDULE_TIME),60),'FM00')||':'||to_char(mod(MAX(TXS.DURATION_FRAME),60),'FM00') "SCHEDULED DURATION"
FROM TX_RECON_INSTANCE_VIEW TXR, TX_SCHEDULE TXS, TX_SCHEDULE_RECON TXREC
WHERE TXR.TX_DATE=20100926 AND TXR.TX_TYPE='P'
AND TXR.TX_ID=TXREC.RECON_TX_ID(+)
AND TXREC.BASE_TX_ID=TXS.TX_ID(+)
GROUP BY TXR.TX_DATE, TXR.ITEM_ID
ORDER BY TXR.TX_DATE, TXR.ITEM_ID, MAX(TXR.REAL_TIME)--does this work for everyone now? let me know...thanks -
Hi,
Good day everyone! I need help writing a query. I have this table with the following data in them...
ACCT_CODE FSYR YTD_AMT
A123 11 100
A456 11 200
A123 10 50
A456 10 100I want the output to look like this:
ACCT_CODE CURRENT_YEAR(11) PRIOR_YEAR(10)
A123 100 50
A456 200 100The user will input the fiscal year and based on that input, I want to get the prior year value as well.
Thank you for all your help!!
Edited by: user5737516 on Jun 29, 2011 6:48 AM
Edited by: user5737516 on Jun 29, 2011 6:50 AMuser5737516 wrote:
Hi,
Good day everyone! I need help writing a query. I have this table with the following data in them...
ACCT_CODE FSYR YTD_AMT
A123 11 100
A456 11 200
A123 10 50
A456 10 100
I want the output to look like this:
ACCT_CODE CURRENT_YEAR PRIOR_YEAR
A123 100 50
A456 200 100
The user will input the fiscal year and based on that input, I want to get the prior year value as well.
Thank you for all your help!!what is prior year? -
Need Help with Creating the SQl query
Hi,
SQL query gurus...
INFORMATION:
I have two table, CURRENT and PREVIOUS.(Table Defs below).
CURRENT:
Column1 - CURR_PARENT
Column2 - CURR_CHILD
Column3 - CURR_CHILD_ATTRIBUTE 1
Column4 - CURR_CHILD_ATTRIBUTE 2
Column5 - CURR_CHILD_ATTRIBUTE 3
PREVIOUS:
Column1 - PREV_PARENT
Column2 - PREV_CHILD
Column3 - PREV_CHILD_ATTRIBUTE 1
Column4 - PREV_CHILD_ATTRIBUTE 2
Column5 - PREV_CHILD_ATTRIBUTE 3
PROBLEM STATEMENT
Here the columns 3 to 5 are the attributes of the Child. Lets assume that I have two loads, One Today which goes to the CURRENT table and one yesterday which goes to the PREVIOUS table. Between these two loads there is a CHANGE in the value for Columns either 3/4/5 or all of them(doesnt matter if one or all).
I want to determine what properties for the child have changed with the help of a MOST efficient SQL query.(PARENT+CHILD is unique key). The Database is ofcourse ORACLE.
Please help.
Regards,
ParagHi,
The last message was not posted by the same user_name that started the thread.
Please don't do that: it's confusing.
Earlier replies give you the information you want, with one row of output (maximum) per row in current_tbl. There may be 1, 2 or 3 changes on a row.
You just have to unpivot that data to get one row for every change, like this:
WITH single_row AS
SELECT c.curr_parent
, c.curr_child
, c.curr_child_attribute1
, c.curr_child_attribute2
, c.curr_child_attribute3
, DECODE (c.curr_child_attribute1, p.prev_child_attribute1, 0, 1) AS diff1
, DECODE (c.curr_child_attribute2, p.prev_child_attribute2, 0, 2) AS diff2
, DECODE (c.curr_child_attribute3, p.prev_child_attribute3, 0, 3) AS diff3
FROM current_tbl c
JOIN previous_tbl p ON c.curr_parent = p.prev_parent
AND c.curr_child = p.prev_child
WHERE c.curr_child_attribute1 != p.prev_child_attribute1
OR c.curr_child_attribute2 != p.prev_child_attribute2
OR c.curr_child_attribute3 != p.prev_child_attribute3
, cntr AS
SELECT LEVEL AS n
FROM dual
CONNECT BY LEVEL <= 3
SELECT s.curr_parent AS parent
, s.curr_child AS child
, CASE c.n
WHEN 1 THEN s.curr_child_attribute1
WHEN 2 THEN s.curr_child_attribute2
WHEN 3 THEN s.curr_child_attribute3
END AS attribute
, c.n AS attribute_value
FROM single_row s
JOIN cntr c ON c.n IN ( s.diff1
, s.diff2
, s.diff3
ORDER BY attribute_value
, parent
, child
; -
Need Help With Query Using Aggregation
If I have a table, defined like this:
CREATE TABLE range_test
range_id NUMBER(20) NOT NULL,
grade CHAR(1) NOT NULL,
lower_bound_of_range NUMBER(5,2) NOT NULL,
upper_bound_of_range NUMBER(5,2) NOT NULL,
received_date_time_stamp TIMESTAMP DEFAULT SYSTIMESTAMP NOT NULL
And I wanted to query the table to find the range associated with the last inserted row for each 'grade' (e.g. 'A', 'B', 'C', etc), how would I go about that?
I want something like the following, but I know that this won't work right:
SELECT
grade,
lower_bounding_of_range,
upper_bounding_of_range,
max(received_date_time_stamp)
FROM
range_test GROUP BY received_date_time_stamp;
Thanks for your help. . .I'm frustrating myself with this one and I think it should be possible without having to use PL/SQL (i.e. SQL aggregate functions or sub-queries should work).Perhaps something along the lines of...
SQL> ed
Wrote file afiedt.buf
1 select deptno, empno, ename, hiredate
2 from emp
3* order by deptno, empno
SQL> /
DEPTNO EMPNO ENAME HIREDATE
10 7782 CLARK 09-JUN-1981 00:00:00
10 7839 KING 17-NOV-1981 00:00:00
10 7934 MILLER 23-JAN-1982 00:00:00
20 7369 SMITH 17-DEC-1980 00:00:00
20 7566 JONES 02-APR-1981 00:00:00
20 7788 SCOTT 19-APR-1987 00:00:00
20 7876 ADAMS 23-MAY-1987 00:00:00
20 7902 FORD 03-DEC-1981 00:00:00
30 7499 ALLEN 20-FEB-1981 00:00:00
30 7521 WARD 22-FEB-1981 00:00:00
30 7654 MARTIN 28-SEP-1981 00:00:00
30 7698 BLAKE 01-MAY-1981 00:00:00
30 7844 TURNER 08-SEP-1981 00:00:00
30 7900 JAMES 03-DEC-1981 00:00:00
14 rows selected.
SQL> ed
Wrote file afiedt.buf
1 select deptno, empno, ename, hiredate
2 from (
3 select deptno, empno, ename, hiredate
4 ,row_number() over (partition by deptno order by hiredate desc) as rn
5 from emp
6 )
7 where rn = 1
8* order by deptno, empno
SQL> /
DEPTNO EMPNO ENAME HIREDATE
10 7934 MILLER 23-JAN-1982 00:00:00
20 7876 ADAMS 23-MAY-1987 00:00:00
30 7900 JAMES 03-DEC-1981 00:00:00
SQL> -
Query off of Oracle using WinSql - Need help with query
I am trying to query off of Oracle using program WinSql.
I have a table(tticpr200110) that has the following sample data:
ITEM CODE T$AMNT
23500076 ACL .0049
23500076 APM 0
23500076 APO .0093
23500076 EXP .0001
23500076 RES .0072
and what I want it to look like is:
ITEM ACL APM APO EXP RES
23500076 0.0049 0 0.0093 0.0001 0.0072
(actually I need the last 2 columns added together to be MATL-but can deal with that down the road).
Seems simple enough, but I don't know to put into the columns.
Any help would be GREATLY appreciated as soon as possible would be even better.My table - tticpr200110 when it runs I get the following sample data for part number 23500076:
The first coloumn ITEM is the part number.
The second column CODE is 1 of 5 different cost codes
The third column is the cost for that code for that part.
ITEM CODE AMNT
23500076 ACL 0.0049
23500076 APM 0.0000
23500076 APO 0.0093
23500076 EXP 0.0001
23500076 RES 0.0072
I want to make a query that makes the data look like this:
ITEM ACL APM APO EXP RES
23500076 0.0049 0.0000 0.0093 0.0001 0.0072
(similar to a pivot table in excel or acess)
I hope this helps better.
Thanks! -
Need help with Query to determine Credit Memos and Invoices
Hi All
Thanks for all the help here.
I need a query to determine any credits or invoices issued within a given period.
OINV and ORIN with UNION ALL?
Please advise any help.
Thank you!Hi Daniel,
Please check below Query.
SELECT T0.[DocNum] as 'Invice No', T0.[DocDate] as 'Invoice Date', T0.[CardName] as 'Invoiced Customer', T3.[DocNum] as 'Credit Memo No', T3.[DocDate] as 'Credit Mamo Date', T3.[CardName] as 'Credit Memo Customer' FROM OINV T0 LEFT JOIN INV1 T1 ON T0.[DocEntry] = T1.[DocEntry] LEFT JOIN RIN1 T2 ON T2.[BaseEntry] = T1.[DocEntry] AND T2.[BaseLine] = T1.[LineNum] LEFT JOIN ORIN T3 ON T2.[DocEntry] = T3.[DocEntry] WHERE T0.[DocDate] >=[%3] AND T0.[DocDate] <=[%4]
Hope this helps
Regards::::
Atul Chakraborty -
Need help with query for converting columns to rows
Hello,
I know this is a very common question asked in the forum. I have searched regading this, i did find some threads, but i was not able to achieve what i require from the answers posted. So anybody please help me.
I have a table which is having multiple columns as follows:
Insert into table_1 (X,Y,Z,A,B,C,D,E,F,G,H,I) values (0,0,2,0,0,1,3,0,0,0,0,0);I want to convert the result into a two column, multiple rows i.e., I want the result as follows:
Col1 Col2
X 0
Y 0
Z 2
A 0
B 0
C 1
D 3
E 0
F 0
G 0
H 0
I 0Please anybody help me in writing the query for this..Is this what you are expecting:
SQL> WITH T AS
2 (
3 SELECT 0 X, 0 Y, 2 Z, 0 A, 0 B, 1 C, 3 D, 0 E, 0 F, 0 G, 0 H, 0 I FROM DUAL
4 )
5 SELECT 'X' col1, X col2 FROM T
6 UNION ALL
7 SELECT 'Y' col1, Y col2 FROM T
8 UNION ALL
9 SELECT 'Z' col1, Z col2 FROM T
10 UNION ALL
11 SELECT 'A' col1, A col2 FROM T
12 UNION ALL
13 SELECT 'B' col1, B col2 FROM T
14 UNION ALL
15 SELECT 'C' col1, C col2 FROM T
16 UNION ALL
17 SELECT 'D' col1, D col2 FROM T
18 UNION ALL
19 SELECT 'E' col1, E col2 FROM T
20 UNION ALL
21 SELECT 'F' col1, F col2 FROM T
22 UNION ALL
23 SELECT 'G' col1, G col2 FROM T
24 UNION ALL
25 SELECT 'H' col1, H col2 FROM T
26 UNION ALL
27 SELECT 'I' col1, I col2 FROM T
28 /
C COL2
X 0
Y 0
Z 2
A 0
B 0
C 1
D 3
E 0
F 0
G 0
H 0
C COL2
I 0
12 rows selected. -
Hey I'm trying to get a working understanding of some of the basics behind SQL, I've composed a few questions that I think may help me with this. Anyone that can help me with any of them will greatly help me thanks.
1. How to create synonym for tables?
2. How to describe the structure of tables?
3. How to list the contents of tables?
4. How to create a table named with the same structure as another table?
5. How to copy rows with less than a certain criteria in value (e.g. Price<$5.00) into another table?
6. How to change the data type to e.g. NUMBER(6)?
7. How to add a new column named with data type e.g. VARCHAR2(10)?
8. How to change a specific field within a table (e.g. For ORDER_NUMBER 12489, change the C_NUMBER to 315)?
9. How to delete a specific row from a table?
10. How to declare a column as the primary key of a table and call it e.g. PK_something?
11. How to show certain columns when another column is less than a certain criteria in value (e.g. Price<$5.00)?
12. How to show certain columns with another column having a certain item class e.g. HW or AP?
13. How to list certain columns when another column e.g. price is between two values?
14. How to list certain columns when another column e.g. price is negative?
15. How to use the IN operator to find certain columns (e.g. first and last name of customers who are serviced by a certain ID)
16. How to find certain columns when one of the columns begins with a particular letter (e.g. A)
18. How to list the contents of the a table sorted in ascending order of item class and, within each item class, sorted in descending order of e.g. price?
19. How to do a count of column in a table?
20. How to sum a column and make rename is something?
21. How to do a count of a column in a table (without repeats e.g. if a certain number repeats more than once than to only count it once)?
22. How to use a subquery to find certain fields in columns when the another column’s fields values are greater than e.g. its average price?848290 wrote:
Hey I'm trying to get a working understanding of some of the basics behind SQL, I've composed a few questions that I think may help me with this. Anyone that can help me with any of them will greatly help me thanks.To use the terminology you have in those questions, you must already have a basic understanding of SQL, so you have exposed yourself as not being the author of such questions.
Please do not ask homework questions without having at least attempted to answer them yourself first and show where you're struggling. -
Need help with Querying XML - XQuery
Hey guys, im new to this stuff so I gained some knowledge from internet but I'm running is some problem that I'll explain below. I have XML like:
<?xml version="1.0" encoding="iso-8859-1"?>
<star:ShowLaborOperations xmlns:star="http://www.starstandard.org/STAR/5" releaseID="5.4.4">
<star:ApplicationArea>
<star:Sender>
<star:CreatorNameCode>AD</star:CreatorNameCode>
<star:SenderNameCode>DDDD</star:SenderNameCode>
<star:SystemVersion>AD2.0</star:SystemVersion>
</star:Sender>
<star:CreationDateTime>2011-05-06T12:51:33Z</star:CreationDateTime>
<star:BODID>A29BF24F-F68E-5CE5-E040-35A54242A0C</star:BODID>
<star:Destination>
<star:DestinationNameCode>AD</star:DestinationNameCode>
</star:Destination>
</star:ApplicationArea>
<star:ShowLaborOperationsDataArea>
<star:Show>
<oagis:ResponseCriteria xmlns:oagis="http://www.openapplications.org/oagis/9">
<oagis:ChangeStatus>
<oagis:Description>Changes</oagis:Description>
</oagis:ChangeStatus>
</oagis:ResponseCriteria>
</star:Show>
<star:LaborOperations>
<star:LaborOperationsHeader>
<star:RequestCode>Changes</star:RequestCode>
<star:LaborOperationsHeaderBase>
<star:DocumentIdentificationGroup>
<star:DocumentIdentification>
<star:DocumentID>ShowOperationCode20110506050532TY</star:DocumentID>
</star:DocumentIdentification>
</star:DocumentIdentificationGroup>
</star:LaborOperationsHeaderBase>
<star:LaborOperationCodes/>
</star:LaborOperationsHeader>
<star:LaborOperationsDetail>
<star:LaborOperationID>001020</star:LaborOperationID>
<star:MajorGroupID>00</star:MajorGroupID>
<star:ComponentGroupID>01</star:ComponentGroupID>
<star:LaborOperationDescription>GAS TANK FILL</star:LaborOperationDescription>
<star:LaborActionCode>OTH</star:LaborActionCode>
<star:LaborOperationsChangeStatus>U</star:LaborOperationsChangeStatus>
<star:Combinations>
<star:VehicleGroupLaborAllowance>
<star:VehicleIdentificationGroup>
<star:VehicleGroupID>JTN</star:VehicleGroupID>
<star:VehicleID>JJXB0</star:VehicleID>
</star:VehicleIdentificationGroup>
<star:ChangeStatus>A</star:ChangeStatus>
<star:LaborAllowanceMeasure unitCode="hour">0.0</star:LaborAllowanceMeasure>
<star:ChargeHoursIndicator>false</star:ChargeHoursIndicator>
</star:VehicleGroupLaborAllowance>
<star:VehicleGroupLaborAllowance>
<star:VehicleIdentificationGroup>
<star:VehicleGroupID>JTM</star:VehicleGroupID>
<star:VehicleID>ZF32V</star:VehicleID>
</star:VehicleIdentificationGroup>
<star:ChangeStatus>U</star:ChangeStatus>
<star:LaborAllowanceMeasure unitCode="hour">0.6</star:LaborAllowanceMeasure>
<star:ChargeHoursIndicator>true</star:ChargeHoursIndicator>
</star:VehicleGroupLaborAllowance>
</star:Combinations>
</star:LaborOperationsDetail>
</star:LaborOperations>
</star:ShowLaborOperationsDataArea>
</star:ShowLaborOperations>
and I wanna be able to see the following result:
<LaborOperationsDetail xmlns="http://www.starstandard.org/STAR/5">
<LaborOperationID>001020</LaborOperationID>
<MajorGroupID>00</MajorGroupID>
<ComponentGroupID>01</ComponentGroupID>
<LaborOperationDescription>GAS TANK FILL</LaborOperationDescription>
<LaborActionCode>OTH</LaborActionCode>
<LaborOperationsChangeStatus>U</LaborOperationsChangeStatus>
<Combinations>
<VehicleGroupLaborAllowance>
<VehicleIdentificationGroup>
<VehicleGroupID>JTN</VehicleGroupID>
<VehicleID>JJXB0</VehicleID>
</VehicleIdentificationGroup>
<ChangeStatus>A</ChangeStatus>
<LaborAllowanceMeasure unitCode="hour">0.0</LaborAllowanceMeasure>
<ChargeHoursIndicator>false</ChargeHoursIndicator>
</VehicleGroupLaborAllowance>
</Combinations>
</LaborOperationsDetail>
for which I'm writing the following query
SELECT OpCodeXMLCol.query('
declare default element namespace "http://www.starstandard.org/STAR/5";
/ShowLaborOperations/ShowLaborOperationsDataArea/LaborOperations/LaborOperationsDetail[Combinations/VehicleGroupLaborAllowance/VehicleIdentificationGroup/VehicleGroupID="JTN"][LaborOperationID="001020"]
-- specified [LaborOperationID="001020"] because there are multiple <LabrOperationDetial> ') as x
FROM XMLData.dbo.OpCodeData
where [ID] = 3 -- primary key for that row containing XML in first snippet
but I'm getting both nodes for <VehicleIdentificatonGroup> whereas I expect to see one containing <VehicleGroupID>JTN</VehicleGroupID> as per filter in query. Please helpThe closest thing which makes sense:
DECLARE @Data XML = N'
<star:ShowLaborOperations xmlns:star="http://www.starstandard.org/STAR/5" releaseID="5.4.4">
<star:ApplicationArea>
<star:Sender>
<star:CreatorNameCode>AD</star:CreatorNameCode>
<star:SenderNameCode>DDDD</star:SenderNameCode>
<star:SystemVersion>AD2.0</star:SystemVersion>
</star:Sender>
<star:CreationDateTime>2011-05-06T12:51:33Z</star:CreationDateTime>
<star:BODID>A29BF24F-F68E-5CE5-E040-35A54242A0C</star:BODID>
<star:Destination>
<star:DestinationNameCode>AD</star:DestinationNameCode>
</star:Destination>
</star:ApplicationArea>
<star:ShowLaborOperationsDataArea>
<star:Show>
<oagis:ResponseCriteria xmlns:oagis="http://www.openapplications.org/oagis/9">
<oagis:ChangeStatus>
<oagis:Description>Changes</oagis:Description>
</oagis:ChangeStatus>
</oagis:ResponseCriteria>
</star:Show>
<star:LaborOperations>
<star:LaborOperationsHeader>
<star:RequestCode>Changes</star:RequestCode>
<star:LaborOperationsHeaderBase>
<star:DocumentIdentificationGroup>
<star:DocumentIdentification>
<star:DocumentID>ShowOperationCode20110506050532TY</star:DocumentID>
</star:DocumentIdentification>
</star:DocumentIdentificationGroup>
</star:LaborOperationsHeaderBase>
<star:LaborOperationCodes/>
</star:LaborOperationsHeader>
<star:LaborOperationsDetail>
<star:LaborOperationID>001020</star:LaborOperationID>
<star:MajorGroupID>00</star:MajorGroupID>
<star:ComponentGroupID>01</star:ComponentGroupID>
<star:LaborOperationDescription>GAS TANK FILL</star:LaborOperationDescription>
<star:LaborActionCode>OTH</star:LaborActionCode>
<star:LaborOperationsChangeStatus>U</star:LaborOperationsChangeStatus>
<star:Combinations>
<star:VehicleGroupLaborAllowance>
<star:VehicleIdentificationGroup>
<star:VehicleGroupID>JTN</star:VehicleGroupID>
<star:VehicleID>JJXB0</star:VehicleID>
</star:VehicleIdentificationGroup>
<star:ChangeStatus>A</star:ChangeStatus>
<star:LaborAllowanceMeasure unitCode="hour">0.0</star:LaborAllowanceMeasure>
<star:ChargeHoursIndicator>false</star:ChargeHoursIndicator>
</star:VehicleGroupLaborAllowance>
<star:VehicleGroupLaborAllowance>
<star:VehicleIdentificationGroup>
<star:VehicleGroupID>JTM</star:VehicleGroupID>
<star:VehicleID>ZF32V</star:VehicleID>
</star:VehicleIdentificationGroup>
<star:ChangeStatus>U</star:ChangeStatus>
<star:LaborAllowanceMeasure unitCode="hour">0.6</star:LaborAllowanceMeasure>
<star:ChargeHoursIndicator>true</star:ChargeHoursIndicator>
</star:VehicleGroupLaborAllowance>
</star:Combinations>
</star:LaborOperationsDetail>
</star:LaborOperations>
</star:ShowLaborOperationsDataArea>
</star:ShowLaborOperations>
WITH XMLNAMESPACES ( DEFAULT 'http://www.starstandard.org/STAR/5' )
SELECT LaborOperationsDetail.query('.'),
VehicleGroupLaborAllowance.query('.')
FROM @Data.nodes('/ShowLaborOperations/ShowLaborOperationsDataArea/LaborOperations/LaborOperationsDetail') A ( LaborOperationsDetail )
CROSS APPLY LaborOperationsDetail.nodes('Combinations/VehicleGroupLaborAllowance[VehicleIdentificationGroup/VehicleGroupID="JTN"]') B ( VehicleGroupLaborAllowance );
Otherwise we need to destruct and rebuild the XML. This in this case imho better done with XSLT. -
Need help with query from .csv file
I am trying to import a csv file with only 1 column in it.
The column will only contain a 9 digit ID number. I want to read
the file then use the contents to query a table to get the names
and other information and display it. Here is what I have so far:
<cffile action="read" file="#form.FiletoUpload#"
variable="csvfile">
<cfloop index="index" list="#csvfile#">
<cfquery name="massimport" datasource="data1">
SELECT * FROM IDTable
WHERE CardNumber = ('#csvfile#')
</cfquery>
</cfloop>
<cfoutput>#Name# #ID# #Site#</cfoutput>
I get no errors but I am not getting any results. Just a
blank page. Does anyone know how to query directly from a csv
import? Thanks.You need to convert your file to a list somehow. Not sure if
this is the most efficient way but, you can use the cfhttp tag to
produce a query. Then your where clause becomes,
where cardnumber in (#quotedvaluelist(query.column)#)
and you won't need a loop. -
It only displays the correct amount of members when I queried only one group like this:
select SMS_R_USER.ResourceID,SMS_R_USER.ResourceType,SMS_R_USER.Name,SMS_R_USER.UniqueUserName,SMS_R_USER.WindowsNTDomain from SMS_R_User where SMS_R_User.SecurityGroupName = "domain\\security group1"
When I tried for multiple groups like shown below, it shows 0 member. I received no error for the query though it is obviously wrong.
select SMS_R_USER.ResourceID,SMS_R_USER.ResourceType,SMS_R_USER.Name,SMS_R_USER.UniqueUserName,SMS_R_USER.WindowsNTDomain from SMS_R_User where SMS_R_User.SecurityGroupName = "domain\\security group1" and SMS_R_User.SecurityGroupName = "domain\\security
group2" and SMS_R_User.SecurityGroupName = "domain\\security group3"
Please check and help me correct it so I can get all members in one collection.
ThanksHi,
If you look to query the amount of members in all the groups you define, use OR instead of AND.
When you use AND, you define that the result must be a member of group1 AND group2 AND group3. You should use OR to get the members of the groups, even though they're just a member of one of them.
select SMS_R_USER.ResourceID,SMS_R_USER.ResourceType,SMS_R_USER.Name,SMS_R_USER.UniqueUserName,SMS_R_USER.WindowsNTDomain from SMS_R_User where SMS_R_User.SecurityGroupName = "domain\\security group1" or SMS_R_User.SecurityGroupName = "domain\\security
group2" or SMS_R_User.SecurityGroupName = "domain\\security group3"
All the best, Jesper Hassing - MCTS SCCM 2012 - MCSA 2012 Server - MCP
Maybe you are looking for
-
How do I add another three computers to my creative cloud license?
I have an educational license for Adobe Creative Cloud, but I want to add another three licenses. When I try to purchase a creative cloud license, you refer me back to the fact that I already have a license. I'd like to purchase another license for a
-
How to fix a looping desktop NOT related to Stuffit?
This very similar to another thread but I feel it's NOT related to it. At first I thought it was related until I got further into the solution. I did download the 2008-08 security update as well as QT 7.6. That's when I think the problem started. The
-
While installing windows with bootcamp error showing "A require Cd/Drive driver is missing" in the middle of installation m not able to install windows on my mac . Please help what to do ??
-
Can't print emails...
Hi there For some reason my Canon IP4700 has decided to stop properly printing emails from my MBP (with latest mountain lion). The printer itself works ok...it prints test pages not problem. It also prints PDFs without a hitch, and photos. However wh
-
Visibility description text form fields in Acrobat Pro
Hi there, I'm making a lot of forms for a client of mine. The major part I'm doing from indesign CC, but a couple of specific alterations I have to do in Acrobat Pro. There is one thing I can't figure out, lets see if I can describe it correctly; One