In line SQL Query - Urgent
In the problem iam calculating a Stock report.In the SQL suppose the relation F does not return any rows , then (D.ACC_QTY + F.RET_QTY) gives null. How to avoid this problem..
SELECT A.CLASSIFICATION_CODE, A.ITEM_ABBR, A.ITEM_DESC,
A.ALT_ITEM_CODE, A.UOM_DESC, A.BASIC_PRICE,
(A.OPENING_QTY + B.ACC_QTY - C.ISS_QTY)
OPENING_STOCK, (D.ACC_QTY + F.RET_QTY) ACCEPT_QTY, E.ISS_QTY,
((A.OPENING_QTY + B.ACC_QTY - C.ISS_QTY)
+ (D.ACC_QTY + F.RET_QTY) - E.ISS_QTY)
QTY_IN_HAND
FROM (SELECT CLASSIFICATION_CODE, ITEM_ABBR, ITEM_DESC,
ALT_ITEM_CODE, NVL(OPENING_QTY, 0)
OPENING_QTY, UOM_MASTER.UOM_DESC,
BASIC_PRICE
FROM ITEM_MASTER, UOM_MASTER
WHERE ITEM_MASTER.UOM_CODE = UOM_MASTER.UOM_CODE)
A,
(SELECT GRN_DETAIL.ITEM_CODE,
SUM(NVL(GRN_DETAIL.ACCEPT_QTY, 0))
ACC_QTY
FROM GRN_HEADER, GRN_DETAIL
WHERE GRN_HEADER.GRN_NO = GRN_DETAIL.GRN_NO AND
GRN_HEADER.GRN_DATE < '01-JAN-2006'
GROUP BY GRN_DETAIL.ITEM_CODE) B,
(SELECT MRN_DETAIL.ITEM_CODE,
SUM(NVL(MRN_DETAIL.ISSUED_QTY, 0))
ISS_QTY
FROM MRN_HEADER, MRN_DETAIL
WHERE MRN_HEADER.MRN_NO = MRN_DETAIL.MRN_NO AND
MRN_HEADER.MRN_DATE < '01-JAN-2006'
GROUP BY MRN_DETAIL.ITEM_CODE) C,
(SELECT GRN_DETAIL.ITEM_CODE,
SUM(NVL(GRN_DETAIL.ACCEPT_QTY, 0))
ACC_QTY
FROM GRN_HEADER, GRN_DETAIL
WHERE GRN_HEADER.GRN_NO = GRN_DETAIL.GRN_NO AND
GRN_HEADER.GRN_DATE BETWEEN
'01-JAN-2006' AND '31-DEC-2006'
GROUP BY GRN_DETAIL.ITEM_CODE) D,
(SELECT MRN_DETAIL.ITEM_CODE,
SUM(NVL(MRN_DETAIL.ISSUED_QTY, 0))
ISS_QTY
FROM MRN_HEADER, MRN_DETAIL
WHERE MRN_HEADER.MRN_NO = MRN_DETAIL.MRN_NO AND
MRN_HEADER.MRN_DATE BETWEEN
'01-JAN-2006' AND '31-DEC-2006'
GROUP BY MRN_DETAIL.ITEM_CODE) E,
(SELECT B.ITEM_CODE,
SUM(NVL(B.QUANTITY_ISSUE,0))
RET_QTY
FROM MATERIAL_MOVEMENT_HEADER A,MATERIAL_MOVEMENT_DETAIL B
WHERE A.SLIP_NO = B.SLIP_NO AND
A.SLIP_DATE BETWEEN
'01-JAN-2006' AND '31-DEC-2006' AND
B.TO_JOB_CODE IS NULL
GROUP BY B.ITEM_CODE) F
WHERE A.ALT_ITEM_CODE = B.ITEM_CODE (+) AND
A.ALT_ITEM_CODE = C.ITEM_CODE (+) AND
A.ALT_ITEM_CODE = D.ITEM_CODE (+) AND
A.ALT_ITEM_CODE = E.ITEM_CODE (+) AND
A.ALT_ITEM_CODE = F.ITEM_CODE (+) AND
A.ALT_ITEM_CODE LIKE 'BOBRNG%017' AND
A.CLASSIFICATION_CODE = 'BO';
Sorry members for writing the word 'Urgent'..and really cutting down on your work.
I am thankful to the person who pointed out my error in the query..it was really simple..should hv solved myself, but even after changing the query with Nvl and changing the business logic to some extent it again fetches no rows..
The sql given underneath is basically a job-wise stock allocation report..
SELECT B.JOB_CODE, A.CLASSIFICATION_CODE, A.ITEM_ABBR,
A.ITEM_DESC, A.ALT_ITEM_CODE, A.UOM_DESC,
A.BASIC_PRICE, (A.OPENING_QTY + (NVL(B.ACC_QTY, 0)
+ NVL(F.RET_IN, 0)) - (NVL(C.ISS_QTY, 0) + NVL(G.RET_OUT,
0))) AS OPENING_STOCK, (NVL(D.ACC_QTY, 0)
+ NVL(H.RET_IN, 0)) RECEIVED, (NVL(E.ISS_QTY, 0)
+ NVL(I.RET_OUT, 0)) ISSUED,
((A.OPENING_QTY + (NVL(B.ACC_QTY, 0) + NVL(F.RET_IN, 0))
- (NVL(C.ISS_QTY, 0) + NVL(G.RET_OUT, 0)))
+ (NVL(D.ACC_QTY, 0) + NVL(H.RET_IN, 0)) - (NVL(E.ISS_QTY,
0) + NVL(I.RET_OUT, 0))) QTY_IN_HAND
FROM (SELECT CLASSIFICATION_CODE, ITEM_ABBR, ITEM_DESC,
ALT_ITEM_CODE, UOM_MASTER.UOM_DESC,
BASIC_PRICE, 0 OPENING_QTY
FROM ITEM_MASTER, UOM_MASTER
WHERE ITEM_MASTER.UOM_CODE = UOM_MASTER.UOM_CODE)
A,
(SELECT GRN_HEADER.JOB_CODE,
GRN_DETAIL.ITEM_CODE,
SUM(NVL(GRN_DETAIL.ACCEPT_QTY, 0))
ACC_QTY
FROM GRN_HEADER, GRN_DETAIL
WHERE GRN_HEADER.GRN_NO = GRN_DETAIL.GRN_NO AND
GRN_HEADER.GRN_DATE < '01-JAN-2006'
GROUP BY GRN_HEADER.JOB_CODE,
GRN_DETAIL.ITEM_CODE) B,
(SELECT B.TO_JOB_CODE, B.ITEM_CODE,
SUM(NVL(B.QUANTITY_ISSUE, 0)) RET_IN
FROM MATERIAL_MOVEMENT_HEADER A,
MATERIAL_MOVEMENT_DETAIL B
WHERE A.SLIP_NO = B.SLIP_NO AND
A.SLIP_DATE < '01-JAN-2006'
GROUP BY B.TO_JOB_CODE, B.ITEM_CODE) F,
(SELECT MRN_HEADER.JOB_CODE,
MRN_DETAIL.ITEM_CODE,
SUM(NVL(MRN_DETAIL.ISSUED_QTY, 0))
ISS_QTY
FROM MRN_HEADER, MRN_DETAIL
WHERE MRN_HEADER.MRN_NO = MRN_DETAIL.MRN_NO AND
MRN_HEADER.MRN_DATE < '01-JAN-2006'
GROUP BY MRN_HEADER.JOB_CODE,
MRN_DETAIL.ITEM_CODE) C,
(SELECT B.JOB_CODE, B.ITEM_CODE,
SUM(NVL(B.QUANTITY_ISSUE, 0)) RET_OUT
FROM MATERIAL_MOVEMENT_HEADER A,
MATERIAL_MOVEMENT_DETAIL B
WHERE A.SLIP_NO = B.SLIP_NO AND
A.SLIP_DATE < '01-JAN-2006'
GROUP BY B.JOB_CODE, B.ITEM_CODE) G,
(SELECT GRN_HEADER.JOB_CODE,
GRN_DETAIL.ITEM_CODE,
SUM(NVL(GRN_DETAIL.ACCEPT_QTY, 0))
ACC_QTY
FROM GRN_HEADER, GRN_DETAIL
WHERE GRN_HEADER.GRN_NO = GRN_DETAIL.GRN_NO AND
GRN_HEADER.GRN_DATE BETWEEN
'01-JAN-2006' AND '31-DEC-2006'
GROUP BY GRN_HEADER.JOB_CODE,
GRN_DETAIL.ITEM_CODE) D,
(SELECT B.TO_JOB_CODE, B.ITEM_CODE,
SUM(NVL(B.QUANTITY_ISSUE, 0)) RET_IN
FROM MATERIAL_MOVEMENT_HEADER A,
MATERIAL_MOVEMENT_DETAIL B
WHERE A.SLIP_NO = B.SLIP_NO AND
A.SLIP_DATE BETWEEN '01-JAN-2006' AND
'31-DEC-2006'
GROUP BY B.TO_JOB_CODE, B.ITEM_CODE) H,
(SELECT MRN_HEADER.JOB_CODE,
MRN_DETAIL.ITEM_CODE,
SUM(NVL(MRN_DETAIL.ISSUED_QTY, 0))
ISS_QTY
FROM MRN_HEADER, MRN_DETAIL
WHERE MRN_HEADER.MRN_NO = MRN_DETAIL.MRN_NO AND
MRN_HEADER.MRN_DATE BETWEEN
'01-JAN-2006' AND '31-DEC-2006'
GROUP BY MRN_HEADER.JOB_CODE,
MRN_DETAIL.ITEM_CODE) E,
(SELECT B.JOB_CODE, B.ITEM_CODE,
SUM(NVL(B.QUANTITY_ISSUE, 0)) RET_OUT
FROM MATERIAL_MOVEMENT_HEADER A,
MATERIAL_MOVEMENT_DETAIL B
WHERE A.SLIP_NO = B.SLIP_NO AND
A.SLIP_DATE BETWEEN '01-JAN-2006' AND
'31-DEC-2006'
GROUP BY B.JOB_CODE, B.ITEM_CODE) I
WHERE A.ALT_ITEM_CODE = B.ITEM_CODE (+) AND
A.ALT_ITEM_CODE = C.ITEM_CODE (+) AND
A.ALT_ITEM_CODE = D.ITEM_CODE (+) AND
A.ALT_ITEM_CODE = E.ITEM_CODE (+) AND
A.ALT_ITEM_CODE = F.ITEM_CODE (+) AND
A.ALT_ITEM_CODE = G.ITEM_CODE (+) AND
A.ALT_ITEM_CODE = H.ITEM_CODE (+) AND
A.ALT_ITEM_CODE = I.ITEM_CODE (+) AND
B.JOB_CODE = C.JOB_CODE AND
B.JOB_CODE = D.JOB_CODE AND
B.JOB_CODE = E.JOB_CODE AND
B.JOB_CODE = F.TO_JOB_CODE AND
B.JOB_CODE = G.JOB_CODE AND
B.JOB_CODE = H.TO_JOB_CODE AND
B.JOB_CODE = I.JOB_CODE AND
A.ALT_ITEM_CODE = 'BOSNVL0004-006-002';
regards,
Similar Messages
-
Hello all,
I have a table that contains more than 100 000 records, structure seen below. I am trying to perform simple queries on this table and it is taking FOREVER for the query to return (in excess of 10 minutes). The only field that contains unique data is the 'key', which I have made the primary key.
Table: WORK
Name Null? Type
ASSIGNMENT_NO NOT NULL NUMBER(2)
START_DATE NOT NULL DATE
END_DATE DATE
ID_NO NOT NULL NUMBER(9)
CODE NOT NULL VARCHAR2(4)
REF_KEY NOT NULL NUMBER(9)
STATUS NOT NULL VARCHAR2(1)
ID_NAME NOT NULL VARCHAR2(30)
LAST_MODIFIED_DATE NOT NULL DATE
KEY NOT NULL NUMBER(9)
As I need to pass into the query varying data I Use a PL/SQL function to call the SQL query.
CREATE OR REPLACE FUNCTION THE_SAMPLE (THE_REF_KEY, THE_ID_NO, PUT_A_DATE_HERE)
RETURN VARCHAR2 IS
CURSOR C IS
SELECT w1.code
FROM work w1
WHERE w1.ref_key = THE_REF_KEY
AND w1.ID_NO = THE_ID_NO
AND w1.status <> 'I'
AND w1.start_date <= PUT_A_DATE_HERE
AND (w1.end_date IS NULL or w1.end_date >= PUT_A_DATE_HERE)
AND w1.start_date = (SELECT MAX(W2.start_date)
FROM work w2
WHERE w2.REF_KEY = W1.REF_KEY
AND w2.ID_NO = W1.ID_NO
AND w2.status <> 'I'
AND w2.start_date <= PUT_A_DATE_HERE
AND (w2.end_date IS NULL or w2.end_date >= PUT_A_DATE_HERE));
out_rec c%ROWTYPE;
begin
begin
open C;
fetch c into out_rec;
CLOSE C;
EXCEPTION
WHEN no_data_found THEN
out_rec.code := NULL;
END;
return out_rec.code;
end THE_SAMPLE;
I am looking for a quick way to accomplish the same task. The main reason is that I am feeding this SQL statement about 20 000 different ref_keys each with a particular ID_NO. Since it seems to take a long time just to process one element I did want crunch data for the next month.
Any help, idea, comments would be greatly welcomed.
Any ideas on how to stream line this?Hummm... I am still working on it, but this is what I have come up with so far:
One way is to do this use this
CURSOR C IS
SELECT w1.code
FROM work w1, (SELECT MAX(w2.start_date) as MAX_DATE
FROM work w2
WHERE w2.ref_key = THE_REF_KEY
AND w2.ID_NO = THE_ID_NO
and w2.status <> 'I'
AND w2.start_date <= PUT_A_DATE_HERE
AND (w2.end_date IS NULL or w2.end_date >= PUT_A_DATE_HERE)) GET_MAX
WHERE w1.ref_key = THE_REF_KEY
AND w1.ID_NO = THE_ID_NO
and w1.status <> 'I'
AND w1.start_date <= PUT_A_DATE_HERE
AND (w1.end_date IS NULL or w1.end_date >= PUT_A_DATE_HERE)
AND w1.start_date = GET_MAX.MAX_DATE;
This way does seem to work a bit faster. I will have to see as the hours pass by.
I am still looking for ways that will process this faster.
null -
Hi Gurus,
Select * from xxa_test1
invoice_type || LOC_CODE|| seq_no
=========================
DOMESTIC A 1
DOMESTIC B 2
DOMESTIC C 3
Select * from xxa_test2
cust_no || cust_name || loc_code
=======================
1001 Test B
1001 Test C
The Requirement is i want sql query to retrive only one record based on seq no if suppose 2 records retrive in that
B is having seqno 2 and c having seq no 3
that sql query should return only one record which is having min seq no. for example in that B, C only B record should return.
If multiple values returned then the program must check based on the seq no it should take min seq no.
i have written this query
Select *
from xxa_test2 t2
where t2.loc_code in (select t1.loc_code
from xxa_test1 t1
order by Seq_no
where above query is correct or not , i am getting problem with this query.
Please let me know its very urgent
Thanks
Manju
Edited by: venu on Jul 26, 2011 12:50 AMSomething like:
SELECT cust_no, cust_name, loc_code
FROM
(with xxa_test1
as (SELECT 'DOMESTIC' invoice_type, 'A' loc_code, 1 seq_no FROM dual
union all
SELECT 'DOMESTIC', 'B', 2 FROM dual
union all
SELECT 'DOMESTIC', 'C', 3 FROM dual),
xxa_test2
as (SELECT 1001 cust_no, 'Test' cust_name, 'B' loc_code FROM dual
union all
SELECT 1001 , 'Test' , 'C' FROM dual)
SELECT cust_no, cust_name, t2.loc_code, seq_no, min(seq_no) over() min_seq
FROM xxa_test2 t2,xxa_test1 t1
WHERE t2.loc_code = t1.loc_code)
WHERE seq_no = min_seq
SQL> /
CUST_NO CUST L
1001 Test B -
Help me write a SQL query; urgent
Hi, can somebody please help me write a SQL query.
I have 3 tables each with the same column names (Col1, Col2, Col3). Col1 is PK with Unique Constraint.
I wanted to add values of Col2 and Col3 (from all 3 tables) and put it in a separate table (i.e aggregated) of all values found in Col1.
Does anybody help me please ?
thanks alot.Please don't mark your question as urgent. You've been around here long enough that you should know that it will not get your question anwered any faster, and may just irritate people into not answering at all.
I'm not sure exactly what you want.
Are you saying you want t1.c2 + t1.c3 + t2.c2 + t2.c3+ t3.c2 + t3.c3 for the rows that have the same c1 in all three tables?
If so, it would be like this, I think: insert into t4
select t1.c1
, t1.c2 + t1.c3 + t2.c2 + t2.c3+ t3.c2 + t3.c3
from t1, t2, t3
where t2.c1 = t1.c1
and t3.c1 = t1.c1If that's not what you want, please clarify.
And next time maybe you should post your SQL question in a SQL forum. -
Need sql query or pl/sql query urgent
Hi Experts,
The requirement is that
SELECT 'N' flag, sysdate init_date,
'' vendor_name,
DECODE (pa.address_type,
'P', 'Present Address',
'R', 'Permanent Address',
pa.address_type
) address_type,
pa.address_line1
|| ','
|| pa.address_line2
|| ','
|| pa.town_or_city
|| ','
|| meaning
|| ','
|| pa.POSTAL_CODE "Address",
TRUNC (TO_CHAR (pa.date_from, 'YYYY')) YEAR,
TO_CHAR (pa.date_from, 'MON') MONTH,''station
FROM per_addresses pa, fnd_lookup_values, per_all_people_f pf
WHERE (pf.employee_number = :1 or pf.APPLICANT_NUMBER = :2)
and pf.EFFECTIVE_END_DATE='31-DEC-4712'
AND pa.person_id = pf.person_id
AND pa.business_group_id = 42
--AND pa.date_to IS NULL
AND lookup_type = 'PER_US_COUNTRY_CODE'
AND lookup_code = pa.country
AND enabled_flag = 'Y'
AND (end_date_active IS NULL OR end_date_active > SYSDATE)
if i run the above query the output is coming like that
Present Address | Flat No. 1201, OC - 15, Orange County, Plot No. GH - 4,Ahinsa Khand 1st, Indrapuram,Ghaziabad,India,201010| 2,010| JUL
Permanent Address | Q.No. 354, Sector - 3 / B,,Bokaro Steel City,India,827003 |2,010 |JUL
Present Address | 4, Sitara,Chandra Reddy layout, S.T. Bed,Bangalore,India,0| 2,006| JAN
Present Address | 101,,Ushma Urja Apartments,Noida,India,201301 | 2,006 | JUL
Permanent Address | F-19, Maccon Colony, Opp. DAV Shyamali School,,Ranchi,India,834002 | 2,009 | FEB
Present Address | Flat no. 604, B - 1, Krishna Apra Gardens,Vaibhav Khand, Plot - 7,Ghaziabad,India,201010 | 2,009 FEB
But the requirement is the output should come like that
Permanent Address |Q.No. 354, Sector - 3 / B,,Bokaro Steel City,India,827003| 2,010 |JUL
Permanent Address 1| F-19, Maccon Colony, Opp. DAV Shyamali School,,Ranchi,India,834002| 2,009 | FEB
Present Address | Flat No. 1201, OC - 15, Orange County, Plot No. GH - 4,Ahinsa Khand 1st, Indrapuram,Ghaziabad,India,201010| 2,010 | JUL
Present Address 1 | Flat no. 604, B - 1, Krishna Apra Gardens,Vaibhav Khand, Plot - 7,Ghaziabad,India,201010| 2,009 | FEB
Present Address 2 | 101,,Ushma Urja Apartments,Noida,India,201301| 2,006| JUL
Present Address 3 | 4, Sitara,Chandra Reddy layout, S.T. Bed,Bangalore,India,0 | 2,006| JAN
Please provide logice how i need to write a sql query or procedure or function or package
Thanks & Regards
VenuYou can use analytics here :
SELECT
flag,
init_date,
vendor_name,
address_type ||' ' ||rn AS address_type,
Address,
YEAR,
MONTH,
station
FROM
SELECT
'N' flag,
sysdate init_date,
'' vendor_name,
DECODE (pa.address_type, 'P', 'Present Address', 'R','Permanent Address', pa.address_type ) address_type,
row_number() over(partition BY pa.address_type order by 1) AS rn,
pa.address_line1
|| ','
|| pa.address_line2
|| ','
|| pa.town_or_city
|| ','
|| meaning
|| ','
|| pa.POSTAL_CODE "Address",
TRUNC (TO_CHAR (pa.date_from, 'YYYY')) YEAR,
TO_CHAR (pa.date_from, 'MON') MONTH,
'' station
FROM
per_addresses pa,
fnd_lookup_values,
per_all_people_f pf
WHERE
pf.employee_number = :1
OR pf.APPLICANT_NUMBER = :2
AND pf.EFFECTIVE_END_DATE='31-DEC-4712'
AND pa.person_id = pf.person_id
AND pa.business_group_id = 42
--AND pa.date_to IS NULL
AND lookup_type = 'PER_US_COUNTRY_CODE'
AND lookup_code = pa.country
AND enabled_flag = 'Y'
AND
end_date_active IS NULL
OR end_date_active > SYSDATE
); -
Sql query - urgent major problem
If I have the following sql query and I would like to perform a select on this how would I do it.
select StudentNo, CourseCode, Year, ExamMark from **
where CourseCode='ELE304' AND Year=1999;
**select COURSESTUDENT.StudentNo, COURSESTUDENT.CourseCode, COURSESTUDENT.Year, MARKS.ExamMark, MARKS.EntryNo AS RESULT FROM
COURSESTUDENT LEFT JOIN MARKS ON COURSESTUDENT.StudentNo=MARKS.StudentNo AND COURSESTUDENT.CourseCode='ELE304' AND
MARKS.CourseCode='ELE304' AND COURSESTUDENT.Year=1999 AND MARKS.Year=1999;Ive been trying to get this sql query correct the whole day this is a joke .......
Someone must know what the prob is...
thanks
tzaf -
Need a SQL Query (URGENT)
Hi Folks,
I have 2 tables, in which the 1st one has 200 columns and 2 table had 2 columns.. There is one common column for both the tables, but there is little change in schema of the tables...The common col in 2nd table is a primary key but the same column in the 1st table is a ordinary one..The data type for the common column is same...
Now i need to write a query to select 199columns(except the common column)from the 1st table and the other column(2nd col)other than the common column frm the 2nd table for "table1.commoncolumn=table2.commoncolumn"......
I had tried the natural join but its nt working in my informix sql database....I also tried by explicitly mentioning column names like "select column1,column2....column199,table2.column2 from table1,table2 where table1.commoncolumn=table2.commoncolumn", but its having a severe performance impact.......
Can some please suggest a query for the above one?? Thankx in advance..Please gimme possible solutions & suggestions regarding the above query....
The informix z forum very slow...The problem is, you labeled your questions badly. As this is a forum of volunteers people tend to react badly to the use of the word "urgent" in the subject line. Nobody's question matters more than anybody else's. In fact some regulars won't answer questions with "urgent" in the strapline as a matter of principle.
Then when we get to actually read your question it turns out to be a question about Informix. I guess not many people here use Informix so your potential pool of responders is pretty small (for instance I'm not even sure how to spell it).
It's not our fault the Informix forums are so lame.
Anyway, what I suggest is you repost your question with a new title: (Off topic) Need help with an INFORMIX query.
At least that will attract people who might be able to answer your question. Then you need to include the actual query you're running and all the supporting details necessary for people to understand the nature of the performance impact.
You need to ask the right people and you need to ask the right question. This is standard etiquette (and indeed common sense) regardless of which forum you're using.
Cheers, APC
Blog : http://radiofreetooting.blogspot.com/ -
I would be thankful if anyone could please advise on the sql question as follows:
id1,dept1,JOHN,12-12-1991
id2,dept1,JOHN,12-12-1992
id3,dept1,JOHN,12-12-1993
id4,dept1,SMITH,11-10-1994
id5,dept1,SMITH,12-12-1995
id6,dept1,SMITH,12-12-1996
id7,dept1,CHRIS,07-07-1997
id8,dept1,CHRIS,12-12-1998
I need a query to get the the data when a particular employee was replaced
as follows:
name,date_replaced
JOHN,11-10-1993
SMITH,07-07-1997
CHRIS,null
Any suggestions are most welcome.1 select distinct name, last_value(NextHired) over (ORDER BY dept,name)
2 from
3 (with emp as
4 (select 'id1' id,
5 'dept1' dept,
6 'JOHN' name,
7 to_date('12-12-1991' ,'DD-MM-YYYY') hiredate from dual
8 union
9 select 'id2','dept1','JOHN',to_date('12-12-1992' ,'DD-MM-YYYY') from dual
10 union
11 select 'id3','dept1','JOHN',to_date('12-12-1993' ,'DD-MM-YYYY') from dual
12 union
13 select 'id4','dept1','SMITH',to_date('11-10-1994','DD-MM-YYYY') from dual
14 union
15 select 'id5','dept1','SMITH',to_date('12-12-1995','DD-MM-YYYY') from dual
16 union
17 select 'id6','dept1','SMITH',to_date('12-12-1996','DD-MM-YYYY') from dual
18 union
19 select 'id7','dept1','CHRIS',to_date('07-07-1997','DD-MM-YYYY') from dual
20 union
21 select 'id8','dept1','CHRIS',to_date('12-12-1998','DD-MM-YYYY') from dual)
22 select id,name, dept,lead (hiredate,1) OVER (ORDER BY hiredate) AS NextHired
23 from emp
24 order by id, dept)
25* order by last_value(NextHired) over (ORDER BY dept,name)
SQL> /
JOHN 11/10/94
SMITH 07/07/97
CHRIS
SQL> Nicolas.
Message was edited by:
N. Gasparotto
Hmm, rajeevm, you wrote JOHN,11-10-1993, but it seems it's a mistake... isn't it ? -
SQL Query Urgent..pls help
Dear Experts,
Table.
C_id Purity
1 100
2 100
10 100
11 100
12 100
Ranking Regions by Size You have to list all regions in the table, and you have to list them according to their size.
you need to list all regions of two or more containers with a purity of 100, and you need to sort that list by the number of containers in each region.
The output should be something like this:
RegBeg RegEnd RegionSize
10 12 3
1 2 2
Kindly help me,
BasavLooks like a homework assignment.
Perhaps you can explain to your tutor how the tabbibitosan method works...
SQL> ed
Wrote file afiedt.buf
1 with t as (select 1 as C_id, 100 as Purity from dual union all
2 select 2, 100 from dual union all
3 select 4, 100 from dual union all
4 select 5, 100 from dual union all
5 select 6, 50 from dual union all
6 select 7, 100 from dual union all
7 select 10, 100 from dual union all
8 select 11, 100 from dual union all
9 select 12, 100 from dual)
10 --
11 -- use tabbibitosan method to group data
12 select min(c_id) as min_c_id
13 ,max(c_id) as max_c_id
14 ,count(*) as grp_size
15 from t
16 where purity = 100
17 group by c_id-rownum
18 having count(*) > 1
19* order by 3 desc, 1
SQL> /
MIN_C_ID MAX_C_ID GRP_SIZE
10 12 3
1 2 2
4 5 2... if you can understand it. ;) -
SQL QUERY, URGENT PLEASE HELP .....
Hi,
There is a table which stores the sales record, weekly basis.
For example
WEEK______ ITEMNO______SALES______QTY
200201_____10001______10,000______50
200202_____10001______18,000______55
200230_____10001______55,000_____330
Now the report should display the week nos and a Cumulative average.
like
ITEM NO - 10001
WEEKNO____WK-AVG____13WK-AVG____26WK-AVG____52WK-AVG
200201
200202
200203
200230
The WK-AVG is calculated for that perticular (weeks sales /weeks qty) but for 13WK-AVG,26-AVG and 52WK-AVG , The calculationis the (cumulative of last 13 week sales /cumulative of last 13 wk qty)
for example at week 200230 the 13WK-AVG should be
(cumulative sales from week 200218 to 200230 / cumulative qty from week 200218 to 200230 )
the same hold good for 26WK-AVG AND 52WK-AVG. Please suggest me how to do it . This is very urgent . Please help me .
Thanks
FerozFeroz,
One way is to use subselects. E.g.,
SELECT WK_AVG, 13WK_AVG, 26WK_AVG, 56WK_AVG FROM
(SELECT (SALES/QTY) AS WK_AVG FROM TABLE WHERE ITEMNO=x AND WEEK = ...),
(SELECT (SUM(SALES)/SUM(QTY)) AS 13WK_AVG WHERE ITEMNO=X AND WEEK > Y AND WEEK <= Z),
hope this helps.
regards,
Stewart -
SQL query urgent helps needed!!!
Hi all,
I got the following query :-
SELECT RH.REQUEST_NUMBER,
MSIK.CONCATENATED_SEGMENTS,
MSIK.DESCRIPTION,
RL.FROM_SUBINVENTORY_CODE,
RL.UOM_CODE,
RL.QUANTITY,
PP.FULL_NAME ,
M.TRANSACTION_QUANTITY
FROM MTL_TXN_REQUEST_HEADERS RH,
MTL_TXN_REQUEST_LINES RL,
MTL_SYSTEM_ITEMS_KFV MSIK,
FND_USER FU,
PER_PEOPLE_V7 PP,
( SELECT MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE, SUM(MOQ.TRANSACTION_QUANTITY)
FROM MTL_ONHAND_QUANTITIES MOQ, MTL_SYSTEM_ITEMS_KFV MSIK2
WHERE MSIK2.INVENTORY_ITEM_ID = MOQ.INVENTORY_ITEM_ID
AND MSIK2.ORGANIZATION_ID = 8
AND MOQ.SUBINVENTORY_CODE LIKE 'ST%'
GROUP BY MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE) M
WHERE
RH.HEADER_STATUS IN(3,7,8)
AND RH.MOVE_ORDER_TYPE IN(1,2)
and rh.header_id = rl.header_id
AND MSIK.INVENTORY_ITEM_ID = RL.INVENTORY_ITEM_ID
AND MSIK.ORGANIZATION_ID = 8
AND RL.FROM_SUBINVENTORY_CODE LIKE 'ST%'
AND RH.CREATED_BY = FU.USER_ID
AND FU.EMPLOYEE_ID = PP.PERSON_ID
However, when I try to run I got the invalid column for m.transaction_quantity ??? why? does it b'cos of the group sum that I used ?
My intention of this query to display the sum of total qty from the mtl_onhand_quantities table.
Please helps.
Thanks.
Rgds
Limsorry if its too late.....
my guess is alias the SUM(MOQ.TRANSACTION_QUANTITY) in the sub-query table (M) as TRANSACTION_QUANTITY.
-------- code snippet---------
FND_USER FU,
PER_PEOPLE_V7 PP,
( SELECT MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE,
SUM(MOQ.TRANSACTION_QUANTITY) TRANSACTION_QUANTITY <------------------------------------This is important
FROM MTL_ONHAND_QUANTITIES MOQ, MTL_SYSTEM_ITEMS_KFV MSIK2
WHERE MSIK2.INVENTORY_ITEM_ID = MOQ.INVENTORY_ITEM_ID
AND MSIK2.ORGANIZATION_ID = 8
AND MOQ.SUBINVENTORY_CODE LIKE 'ST%'
GROUP BY MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE) M
WHERE
RH.HEADER_STATUS IN(3,7,8)
AND RH.MOVE_ORDER_TYPE IN(1,2)
--------------code snippet ends------------------------
hope this helps, -
hi ,
i have data like this
cola colb colc
123 12 a
123 12 b
123 12 a
124 12 d
124 12 f
we have to loop throuhj all the values associated with colc for each cola and colb, if all the values are not in (a and b), then i return the distinct on cola and colb
in the above instnace , the retruned value is 124 12, since none of the values in colc are in (a and b)
pls help, txPlease see below...
DECLARE @TABLE TABLE
(cola INT, colb INT, colc CHAR(10))
INSERT INTO @TABLE VALUES(123, 12, 'a'), (123, 12, 'b'), (123, 12, 'a')
, (124, 12, 'd'), (124, 12, 'f'), (123, 12, 'c')
SELECT * FROM @TABLE b WHERE b.colc = 'a' OR b.colc = 'b'
;WITH CTE AS
(SELECT DISTINCT cola, colb FROM @TABLE b WHERE b.colc = 'a' OR b.colc = 'b')
SELECT DISTINCT a.cola, a.colb
FROM @TABLE a
LEFT JOIN CTE b ON a.cola = b.cola AND a.colb = b.colb
WHERE b.cola IS NULL AND b.colb IS NULL
Please mark as answer, if this has answered your question.
Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles. -
How to configure a sql query of 110 lines in a DB Adapter
Hi all,
I have a sql query which is 110 lines and i need to use "select"operation in DB Adapter.I dont understand where to put the query in DB Adapter.I worked on a sql query which is 3 or 4 lines but this is the first time iam working on a sql Query with 110 lines.
Please help me.Give me sme link or any document that i can refer.
Thanks,
KiranHI,
Please use the option of Custom Sql and paste it there.
it does not matter what operation are you using but the xsd will form accordingly.
If you need to do only via Select operation in the wizard, than select the tables and add pararmeters in the next screen and try to give the logic there.
I feel the best thing to do would be with the Custom Sql query.
And whatever variables you need to pass dyanamically.
Just put an # symbol before to the column name .
The variable will be formed.
Thanks,
Tirumala Dixit. -
SQL Query if or case omit fields but not line.
I have the below SQL Query my goal is to not show Aging or Storage Date if QTY is greater than 0.
I know I can omit the line but I still want to show just not those two fields is this possible?
Select sl.SKU, sl.LOC, (editdate) AS "Storage Date", CAST(sysdate-editdate AS DECIMAL(10,2)) AS Aging, sl.QTY, sl.QTYALLOCATED
From skuxloc sl
Where sl.SKU in ('315A6112-29','315A6112-33')
This is what I'm looking for:
Work Smarter Not HarderAre you working with OracleSQL, There is no sysdate in SQL Server.
Select sl.SKU, sl.LOC,
case when sl.QTY =0 then '' else editdate end AS 'Storage Date',
case when sl.QTY =0 then '' else CAST(sysdate-editdate AS DECIMAL(10,2)) END
AS Aging,
sl.QTY, sl.QTYALLOCATED
From skuxloc sl
Where sl.SKU in ('315A6112-29','315A6112-33')
If you are working with Oracle, You can try decode.
http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions040.htm
http://www.dba-oracle.com/t_decode_function.htm
--Prashanth -
New Line Character in SQL Query
Dear All,
I am wondering if some one tell me how to insert new line character in the SQL Query Output for example I need out put in the following format. Every line on new line.
The total count is:
Registration: 1111
Fees paid: 2222
Admission Done: 3333
Total:4000
Many thanksHi
SQL> select
2 'The total count is:
3 Registration: 1111
4 Fees paid: 2222
5 Admission Done: 3333
6 Total:4000
7 ' dummy_txt from dual
8 /
DUMMY_TXT
The total count is:
Registration: 1111
Fees paid: 2222
Admission Done: 3333
Total:4000
SQL>
SQL> select 'a'||chr(10)||'b' from dual;
'A'
a
b
SQL> T
Maybe you are looking for
-
When I try to stream the audio never works and it doesn't show dazzle under audio. I heard that you click the tool next to capture device go to crossbar and click audio decoder out for output and audio line in for input. I click ok and and check agai
-
Skype Account Hacked... Next Steps?
Well, as the title says, my skype account got hacked. I think I was a victim of a fake skype email. The hacker managed to change the password to the account as well as the registered email. As soon as I realized it was stolen, I put in an account rec
-
Problem calling Oracle function from Access 2007 / ADO
Hopefully, I'm posting this in the correct forum. I'm also posting on an Access forum as I'm not entirely sure where the issue lies. I'm calling an Oracle function from Access 2007 using an ADO Command object. The function takes three input parameter
-
Hi Gurus, we are implementing KANBAN with WM for VERP materials in the pharmacology factory. We actived the replenishment strategy 0006 (for WM) and created a supply area, but SAP didn´t let us use the PK01 to create a new control cycle. System oblig
-
Having trouble verifying remote routing address
I am trying to via powershell ensure that ADFS replication was successful. After i enable the remote mailbox and set the remote routing address on the hybrid servers, i need to find a way to query the msol service to ensure that replication was succe