Query Help (OCRD/CRD1)
Hi All,
Can anyone provide some pointers/help with the following 2 queries we're trying to make:
1. A query to show any Customer which has more than 1 ship-to address in BP Master Data. We have the below, but are not sure how to introduce the greater than 1 condition.
SELECT T0.[CardCode], COUNT(T0.[AdresType]) FROM CRD1 T0 WHERE T0.[AdresType] = 'S' GROUP BY T0.[CardCode]
2. Once we make sure we have at maximum 1 Ship-To address per BP, we want to retrieve the "Ship-To" address for a BP if it exists, and if not, the "Bill-To". Note, there is never more than 1 "Bill-To" address.
SELECT T0.CardCode, T0.CardName, T1.Street, T1.Block, T1.ZipCode FROM OCRD T0 INNER JOIN CRD1 T1 ON T0.CardCode = T1.CardCode WHERE
T0.FrozenFor = 'n' AND T0.CardType = 'c' AND IF EXISTS "Ship-To" THEN ..... ELSE "Bill-To" ???
Hope this makes sense?
Thanks,
Raj
Edited by: Rajiv Agarwalla on Sep 23, 2010 11:10 AM
Hi Istvan,
Thank you for your reply. I manged to get the first query to work correctly, but not the second one. It doesn't seem to retrieve the "Bill-To" address for BPs that only have a "Bill-To" and no "Ship-To". Would you please be able to point out my error in amending your syntax?
SELECT T0.CardCode, T0.CardName ,T1.Street, T1.Block, T1.ZipCode
FROM OCRD T0 INNER JOIN CRD1 T1 ON T0.CardCode = T1.CardCode
WHERE T1.AdresType ='S' AND T0.CardType = 'C'
(The above bit gets the "Ship-To" address for BPs where it exists)
or not exists(Select T1.Street, T1.Block, T1.ZipCode from CRD1 T1
where T1.CardCode=T0.CardCode and T1.AdresType ='B' AND T0.CardType = 'C')
(This bit should be getting the "Bill-To" for BPs where no "Ship-To" exists?)
Thanks!
Rajiv
Similar Messages
-
Query Help:
http://forum.java.sun.com/thread.jsp?forum=45&thread=471180&tstart=15&trange=15
It seems I have confused enough people with my improper presentation of query. Sorry guys. I will restate my question with different table names.
The above was my previous posting, which was not clear..so Iam restating my problem as follows....
I have the following tables
Customer(custID, Name, Address)
Order(custID, OrderID, orderDate)
CreditCard(custID, creditCard#, creditCardType)
Now if I have 3 records in Order with custID 100 and 2 records in CreditCard as
Order:
100,A001,11/22/03
100,A002,11/24/03
100,A003,12/02/03
CreditCard:
100,42323232..., VISA
100,5234234...., MASTER
Now how can I get
custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
data in minimum no. of records....
I think I have made my query clear..
now please help me guys...
thanks so much for your help.You are right.
But frankly the actual tables on my database are not customer,orders and creditcards..but I just tried to reproduce the problem with these tables, please ignore that user needs a refund etc situtaion. If the tables were actually order,creditcards etc..it would have been a problem to be considered.
Can you please help me with the query
if I have m rows in Order and n rows in CreditCard. I will get m*n records, I looking for max(m,n).
With the following fields in my query result,
custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
from Customer, Order, CreditCard tables
Thanks so much for your htlp -
SQL Query Help - Is this possible or impossible????
Hi guys,
I need help with an SQL query that I'm trying to develop. It's very easy to explain but when trying to implement it, I'm struggling to achieve the results that I want.....
For example,
I have 2 tables
The first table is:
1) COMPANY create table company (manufacturer varchar2(25),
date_established date,
location varchar2(25) );My sample test date is:
insert into company values ('Ford', 1902, 'USA');
insert into company values ('BMW', 1910, 'Germany');
insert into company values ('Tata', 1922, 'India');The second table is:
2) MODELS create table models (manufacturer varchar(25),
model varchar2(25),
price number(10),
year date,
current_production_status varchar2(1) ) ;My sample test data is:
insert into models values ('Ford', 'Mondeo', 10000, 2010, 0);
insert into models values ('Ford', 'Galaxy', 12000, 2008, 0);
insert into models values ('Ford', 'Escort', 10000, 1992, 1);
insert into models values ('BMW', '318', 17500, 2010, 0);
insert into models values ('BMW', '535d', 32000, 2006, 0);
insert into models values ('BMW', 'Z4', 10000, 1992, 0);
insert into models values ('Tata', 'Safari', 4000, 1999, 0);
insert into models values ('Tata', 'Sumo', 5500, 1996, 1);
insert into models values ('Tata', 'Maruti', 3500, 1998, 0);And this is my query:
SELECT
com.manufacturer,
com.date_established,
com.location,
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
mod.current_production_status
FROM
company com,
models mod
WHERE
mod.manufacturer = com.manufacturer
and com.manufacturer IN ('Ford', 'BMW', 'Tata')
and mod.current_production_status IN (1,0)
ORDER BY
mod.current_production_status DESCWhat I want the query to output is this:
com.manufacturer com.date_established com.location mod.model mod.price mod.year mod.current_production_status
Ford 1902 USA Escort 10000 1992 1
BMW 1910 Germany - - - 0
Tata 1922 India Sumo 5500 1998 1If current_production_status is 1 it means this particular model has been discontinued
If current_production_status is 0 it means the manufacturer does not have any discontinued models and all are in procuction.
The rule is only one record per manufacturer is allowed to have a current_production_status of 1 (so only one model from the selection the manufactuer offers is allowed to be discontinued).
So the query should output the one row where current_production_status is 1 for each manufacturer.
If for a given manufacturer there are no discontinued models and all have a current_production_status of 0 then ouput a SINGLE row that only includes the data from the COMPANY table (as above). The rest of the columns from the MODELS table should be populated with a '-' (hyphen).
My query as it is above will output all the records where current status is 1 or 0 like this
com.manufacturer com.date_established com.location mod.model mod.price mod.year mod.current_production_status
Ford 1902 USA Escort 10000 1992 1
Tata 1922 India Sumo 5500 1998 1
Ford 1902 USA - - - 0
Ford 1902 USA - - - 0
BMW 1910 Germany - - - 0
BMW 1910 Germany - - - 0
BMW 1910 Germany - - - 0
Tata 1922 India - - - 0
Tata 1922 India - - - 0However this is not what I want.
Any ideas how I can achieve the result I need?
Thanks!
P.S. Database version is '10.2.0.1.0'Hi Vishnu,
Karthiks query helped...
But this is the problem I am facing...
SELECT
com.manufacturer,
com.date_established,
com.location,
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
mod.current_production_status
FROM
company com,
models mod
WHERE
mod.manufacturer = com.manufacturer
and com.manufacturer = 'Ford'
and mod.current_production_status IN (1,0)
ORDER BY
mod.current_production_status DESCThe value of:
and com.manufacturer = 'Ford'will be dependent on front end user input....
When I run the query above I get all the rows where current_production_status is either 1 or 0.
I only require the rows where current_production_status is 1.
So if I amend it to look like this:
and mod.current_production_status = 1This works....
BUT if a user now passes in more than one manufacturer EG:
and com.manufacturer IN ('Ford', 'BMW')The query will only return the one row for Ford where current_production_status is 1. However because BMW has no models where current_production_status is 1 (all 3 are 0), I still want this to be output - as one row....
So like this:
com.manufacturer com.date_established com.location mod.model mod.price mod.year mod.current_production_status
Ford 1902 USA Escort 10000 1992 1
BMW 1910 Germany - - - 0So (hopefully you understand), I want both cases to be catered for.....whether a user enters one manufacturer or more than one...
Thanks you so much!
This is really driving me insane :-( -
hii
i need a query help
i have two tables
the 1st table will look like this
associate id weekid no.of. hours
4000 810 40
4000 820 30
4000 830 60
4000 840 70
2nd table will look like this
associate id weekid no.of.hours
4000 810 40
4000 820 70
4000 830 130
4000 840 200
so when i subtract the last two records frm each other in the second table the value should be equal to the no.of.hours in the first table.. for example
the query shud consider the last record and one before the last record and the difference between two records shud be equal to the value in the 1st table
for example
consider week id 830 and 840
in second table 830=130
840=200
when u subtraced both values the difference shud be equal to value in the 1st table for tht week id
1 ---->>>> 840 - 830
=200 - 130
=70
in first table 840 has 70 hrs
like this it shud check with all records and it shud return only the records which are not equal
regards
srikanthThis..?
sql>select * from t1;
A_ID W_ID HRS
4000 810 40
4000 820 30
4000 830 60
4000 840 70
4000 850 80
sql>select * from t2;
A_ID W_ID HRS
4000 810 40
4000 820 70
4000 830 130
4000 840 200
4000 850 260
sql>
select a_id,w_id,hrs,sum_hrs
from(
select t1.a_id a_id,t1.w_id w_id,t1.hrs hrs,t2.hrs sum_hrs,
t2.hrs - nvl(lag(t2.hrs) over(order by t1.w_id),0) diff
from t1,t2
where t1.w_id = t2.w_id)
where diff != hrs;
A_ID W_ID HRS SUM_HRS
4000 850 80 260 -
Problem in Query with JOIN Function in OCRD CRD1 OCPR tables
Hello Dear Forum Users,
I want to make a query which shows me per business partner from OCRD - Addres; CRD1 - Delivery Address and from OCPR - Contactperson information
Is it possible to show it in one row per Business Partner. Now I get (the classic problem) of several rows and a duplication of the contact persons per (delivery) address.
My query is:
SELECT T0.[CardCode], T0.[CardName], T1.[Address], T1.[Street], T1.[ZipCode], T1.[City], T1.[Country], T1.[U_TelNr], T1.[U_MobNr], T1.[U_OpenTijd], T1.[U_LosIns_1], T1.[U_LosIns_2],T2.[Title], T2.[Name] as 'Voornaam', T2.[Address] as 'Achternaam', T2.[Position] as 'Functie', T2.[Tel1], T2.[Cellolar], T2.[E_MailL], T2.[BirthDate] FROM OCRD T0 LEFT OUTER JOIN CRD1 T1 ON T0.CardCode = T1.CardCode LEFT OUTER JOIN OCPR T2 ON T0.CardCode = T2.CardCode
Can you help me ?
Jos Dielemans - Maastricht
Edited by: J. Dielemans on Apr 29, 2011 4:28 PM
Changed the query with Left Outer JoinI have found the solution myself:
By using the Union All function I could combine two queries. Here is the result:
SELECT
T0.[CardCode], T0.[CardName], T1.[Address] , T1.[Street], T1.[ZipCode], T1.[City], T1.[Country], T1.[U_TelNr], T1.[U_OpenTijd] , T1.[U_LosIns_1] , T1.[U_LosIns_2]'
FROM OCRD T0 LEFT OUTER JOIN CRD1 T1 ON T0.CardCode = T1.CardCode
WHERE T0.[CardCode] >= 'D00000'
Union all
SELECT
T0.[CardCode], T0.[CardName], T2.[Position], T2.[Tel1], T2.[Title], T2.[Name], T2.[Address], T2.[Position], T2.[Tel1], T2.[Cellolar], T2.[E_MailL]
FROM OCRD T0 LEFT OUTER JOIN OCPR T2 ON T0.CardCode = T2.CardCode
WHERE T0.[CardCode] >= 'D00000'
Order by 1
Now i got the result I was looking for. -
Query question, OINV, OCRD, CRD1
When I try to create a query with the 3 tables above when I add the CRD1 the invoice numbers begin to duplicate. Is this a problem with the JOIN statements automatically created by the Generator?
Thanks, Jeff
SELECT *
FROM OINV T0 INNER JOIN OCRD T1 ON T0.CardCode = T1.CardCode
INNER JOIN CRD1 T2 ON T1.CardCode = T2.CardCodehi,
Query will be
SELECT *
FROM OINV T0 INNER JOIN OCRD T1 ON T0.CardCode = T1.CardCode
INNER JOIN CRD1 T2 ON T1.CardCode = T2.CardCode and T2.AdresType = 'B'
Jeyakanthan -
Query Help required to Connect JDT1 with OINV tables
Dear Experts,
I have the following query which gives me the customer ageing report. I want some addtional fields from the OINV table and the document numbering table like Document Series Name, AR Invoice document Number,AR invoice remarks, BP Projects Number ( filled in accounting tab in BP projects) and in the query in Reference 1 column its giving the Invoice Numbers as posted in the Journal but for manual Journal Entries it not giving the Journal Number which I also want to be shown in Ref 1 or a seperat field.
The Query is as under :
select OCRD.cardcode 'Supplier Code',OCRD.cardname 'Name',sysdeb 'Debit Amount',syscred 'Credit Amount',
case JDT1.transtype
when '13' then 'INV'
when '14' then 'AR CN'
when '24' then 'INCOMING'
else 'Other'
end 'Type',
Ref1,
fccurrency 'BP Currency',
CONVERT(VARCHAR(10), refdate, 103)'Posting Date' ,
CONVERT(VARCHAR(10), duedate, 103) 'Due Date',
CONVERT(VARCHAR(10), taxdate, 103) 'Doc Date' ,
CASE
when (DATEDIFF(dd,refdate,current_timestamp))+1 < 31
then
case
when syscred <> 0 then syscred * - 1
else sysdeb
end
end "0-30 days",
case when ((datediff(dd,refdate,current_timestamp))+1 > 30
and (datediff(dd,refdate,current_timestamp))+1< 61)
then
case
when syscred <> 0 then syscred * - 1
else sysdeb
end
end "31 to 60 days",
case when ((datediff(dd,refdate,current_timestamp))+1 > 60
and (datediff(dd,refdate,current_timestamp))+1< 91)
then
case
when syscred <> 0 then syscred * - 1
else sysdeb
end
end "61 to 90 days",
CASE
when (DATEDIFF(dd,refdate,current_timestamp))+1 > 90
then
case
when syscred= 0 then sysdeb
when sysdeb= 0 then syscred * - 1
end
end "90 + days"
from JDT1,OCRD where JDT1.shortname = OCRD.cardcode and cardtype = 'c' and intrnmatch = '0'
ORDER BY OCRD.CARDCODE, taxdate
Would appreciate if you can help me to get a solution in it.
Regards,
KamleshDear Gordon,
While executing the followings modified query it giving an error of
Incorrect Syntax near the keyword 'to' and incorrect Syntax near 'Series'
the query is as under :
{select OCRD.cardcode 'Supplier Code',OCRD.cardname 'Name',sysdeb 'Debit Amount',syscred 'Credit Amount',
case l.transtype
when '13' then 'INV'
when '14' then 'AR CN'
when '24' then 'INCOMING'
else 'Other'
end 'Type',
j.BaseRef'Trans #',
case l.transtype
when '13' then
(Select Comments from OINV where OINV.Transid=j.Transid)
else '-'
end 'Inv.Rem.',
(Select SeriesName From NNM1 Where Series=j.DocSeries and ObjectCode=l.TransType)'Series',
to
(Select Isnull(SeriesName, 'Manual') From NNM1 Where Series=j.DocSeries and ObjectCode=l.TransType)'Series',
l.Ref1,
fccurrency 'BP Currency',
CONVERT(VARCHAR(10), l.refdate, 103)'Posting Date' ,
CONVERT(VARCHAR(10), l.duedate, 103) 'Due Date',
CONVERT(VARCHAR(10), l.taxdate, 103) 'Doc Date' ,
CASE
when (DATEDIFF(dd,l.refdate,current_timestamp))+1 < 31
then
case
when syscred <> 0 then syscred * - 1
else sysdeb
end
end "0-30 days",
case when ((datediff(dd,l.refdate,current_timestamp))+1 > 30
and (datediff(dd,l.refdate,current_timestamp))+1< 61)
then
case
when syscred <> 0 then syscred * - 1
else sysdeb
end
end "31 to 60 days",
case when ((datediff(dd,l.refdate,current_timestamp))+1 > 60
and (datediff(dd,l.refdate,current_timestamp))+1< 91)
then
case
when syscred <> 0 then syscred * - 1
else sysdeb
end
end "61 to 90 days",
CASE
when (DATEDIFF(dd,l.refdate,current_timestamp))+1 > 90
then
case
when syscred= 0 then sysdeb
when sysdeb= 0 then syscred * - 1
end
end "90 + days"
from JDT1 l
Inner Join OJDT j On j.TransId=l.TransId
,OCRD where l.shortname = OCRD.cardcode and cardtype = 'c' and intrnmatch = '0'
ORDER BY OCRD.CARDCODE, l.taxdate}
Regards,
Kamlesh -
Query help on Goods Receipt Query with AP Invoice
Looking for a little help on a query. I would like to list all the goods receipts for a given date range and then display the AP Invoice information (if its been copied to an AP Invoice). I think my problem is in my where clause, I plagerized an SAP query to show GR and AP from a PO as a start. SBO 2005 SP01. Any help would be great appreciated. Thanks
SELECT distinct 'GR',
D0.DocStatus,
D0.DocNum ,
D0.DocDate,
D0.DocDueDate,
D0.DocTotal,
'AP',
I0.DocStatus,
I0.DocNum ,
I0.DocDate,
I0.DocDueDate,
I0.DocTotal,
I0.PaidToDate
FROM
((OPDN D0 inner Join PDN1 D1 on D0.DocEntry = D1.DocEntry)
full outer join
(OPCH I0 inner join PCH1 I1 on I0.DocEntry = I1.DocEntry)
on (I1.BaseType=20 AND D1.DocEntry = I1.BaseEntry AND D1.LineNum=I1.BaseLine))
WHERE
(D1.BaseType=22 AND D1.DocDate>='[%0]' AND D1.DocDate<='[%1]')
OR (I1.BaseType=20 AND I1.BaseEntry IN
(SELECT Distinct DocEntry
FROM PDN1 WHERE BaseType=22 AND DocDate>='[%0]' AND DocDate<='[%1]'))Hi Dalen ,
I believe it is because of the condition
(D1.BaseType=22 AND D1.DocDate>='%0' AND D1.DocDate<='%1')
OR (I1.BaseType=20 AND I1.BaseEntry IN
(SELECT Distinct DocEntry FROM PDN1 WHERE PDN1.BaseType=22 AND DocDate>='%0' AND DocDate<='%1'))
Try changing
D1.BaseType=22 OR D1.DocDate>='%0' AND D1.DocDate<='%1
PDN1.BaseType=22 OR DocDate>='%0' AND DocDate<='%1'))
Lets see what would be the result . Lets have some fun with troubleshooting
See what would be the difference in the result .
Thank you
Bishal -
Query help: query to return column that represents multiple rows
I have a table with a name and location column. The same name can occur multiple times with any arbitrary location, i.e. duplicates are allowed.
I need a query to find all names that occur in both of two separate locations.
For example,
bob usa
bob mexico
dot mexico
dot europe
hal usa
hal europe
sal usa
sal mexico
The query in question, if given the locations usa and mexico, would return bob and sal.
Thanks for any help or advice,
-=beekyHow about this?
SELECT NAME
FROM <LOCATIONS_TABLE>
WHERE LOCATION IN ('usa','mexico')
GROUP BY NAME
HAVING COUNT(DISTINCT LOCATION) >= 2Results:
SQL> WITH person_locations AS
2 (
3 SELECT 'bob' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
4 SELECT 'bob' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
5 SELECT 'dot' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
6 SELECT 'dot' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
7 SELECT 'hal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
8 SELECT 'hal' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
9 SELECT 'sal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
10 SELECT 'sal' AS NAME, 'Mexico' AS LOCATION FROM DUAL
11 )
12 SELECT NAME
13 FROM person_locations
14 WHERE LOCATION IN ('USA','Mexico')
15 GROUP BY NAME
16 HAVING COUNT(DISTINCT LOCATION) >= 2
17 /
NAM
bob
salHTH!
Edited by: Centinul on Oct 15, 2009 2:25 PM
Added sample results. -
QUERY HELP!!! trying to create a query
i'm creating a summary report
i have a table with sale dates
for example i have a table tab_1 and column saleDate as
saleDat
1923
1936
1945
2003
2005
saleDate contains years and there are some missing years where no sale
was made
My report has to display years starting from earliest year
so i have to create a query that starts with 1923
but the problem is that I have to have years that are not in table.
for example i have to display years 1924 which is not in table
so the part of report has to look like
1923 blah blah summary.........
1924 "
1925
1926
2005
2006
upto current year (2006 may not be in the table, but i have to display)
i just need to know the query that can query all the years starting from
the ealiest saleDate to current year
thanks in advancePlease write the query in the following form:
SELECT a.year, --- place other columns from your table.
FROM (SELECT (:start_num + rownum) year
FROM all_tab_columns
WHERE :start_num + rownum <= :end_num) a,
tab_1 b
WHERE a.year = b.saleDat(+);
Note:
1) if your start year and end year are 1923 and 2006. Then input as below:
:start_num = 1922
:end_num = 2006
2) Since for some of the years (1924 etc) may not be there in your so you may need to use NVL to print proper indicators.
3) If you have more than one record in tab_1 for a particular year then group them based year and then use it.
Hope this helps.
- Saumen. -
Pulling open invoices, and paid invoices with details (Query Help).
Hello All,
I am sure I messed something up in my joins. I am looking to pull a report of all invoices OINV for a month, then list details of any payment (if it is paid) next to it from RCT2. It is giving me a list of all of the paid invoices, but even though I have a LEFT JOIN it is not listing any of the invoices without payments.
This is where I am now from the report wizard in Crystal.
SELECT "OINV"."DocNum", "OINV"."SlpCode", "OINV"."CardCode", "OINV"."DocTotal", "OINV"."U_Commission", "OSLP"."SlpName", "RCT2"."DcntSum", "ORCT"."TaxDate", "OINV"."DocEntry", "OINV"."TotalExpns", "OINV"."CANCELED", "ORCT"."Canceled", "ORCT"."DocNum", "RCT2"."InvType"
FROM ("DBName"."dbo"."OINV" "OINV" LEFT OUTER JOIN "DBName"."dbo"."OSLP" "OSLP" ON "OINV"."SlpCode"="OSLP"."SlpCode")
INNER JOIN ("DBName"."dbo"."ORCT" "ORCT" INNER JOIN "DBName"."dbo"."RCT2" "RCT2" ON "ORCT"."DocNum"="RCT2"."DocNum")
ON "OINV"."DocEntry"="RCT2"."DocEntry"
WHERE "OINV"."CANCELED"='N' AND "ORCT"."Canceled"='N' AND "RCT2"."InvType"<=N'14'
ORDER BY "OINV"."SlpCode", "ORCT"."DocNum", "ORCT"."TaxDate"
Thank you in advance for any help you can give me.Hello Kiran,
I thought about that, but my purposes for running the report is to determine commission based on the date that the invoice was paid, I need the TaxDate in ORCT as it relates to the payment in RCT2.
Removing the ORCT.cancelled condition and the RCT2.invtype conditions now pulls all of the invoices, paid and unpaid. I know now I cant have them in my query, when the record does not exist in ORCT it doesnt have a value for cancelled, and when there is no record in RCT2 there is no invtype, and is filtered.
Maybe I can say where ORCT.Canelled = 'N' OR ORCT.Cancelled = NULL, but I dont know if that would work. -
Query Help for reporting on last receipt qty
SBO Version: 8.82 PL11
Hello Forum,
I am looking for some help devising a command behind a crystal report. We are hoping to achieve the last receipt quantity. To arrive at this we would like it to get the last GRPO for an item and total the quantity on that particular GRPO. In addition to this, we want to consider all the lines on the document and SUM them.
At present, the query I have is as follows:
Select SUM(c0.Quantity) from PDN1 c0 WHERE c0.ItemCode = T1.ItemCode AND Shipdate = (select Max(ShipDate) from PDN1 C0 INNER JOIN OPDN c1 ON c0.DocEntry = c1.DocEntry where C0.Itemcode =T1.ItemCode AND c1.DocStatus <> 'C'))
Any assistance would be greatly received.
Thanks
SarahHi Sarah,
Please repost to the SAP Business One Application space.
-Abhilash -
SQL Query help ( On connect By level clause)
Hi all,
I have this query developed with data in with clause.
With dat As
select '@AAA @SSS @DDD' col1 from dual union all
select '@ZZZ @XXX @TTT @RRR @ZZA' col1 from dual
Select regexp_substr( col1 , '[^@][A-Z]+',1,level) Show from dat
connect by level <= regexp_count(col1, '@');Current output :-
SHOW
AAA
SSS
DDD
RRR
ZZA
TTT
RRR
ZZA
XXX
DDD
RRR
SHOW
ZZA
TTT
RRR
ZZA
. . .1st row comes fine, But next row data is getting duplicated. And total record count = 30. I tried with some but didn't work.
Expected output :-
SHOW
AAA
SSS
DDD
ZZZ
XXX
TTT
RRR
ZZAI need some change on my query and I am not able to find that. So anybody can add on that or can also provide some different solution too.
Thanks!
AshutoshHi,
When you use something like "CONNECT BY LEVEL <= x", then at least one of the following must be true:
(a) the table has no more than 1 row
(b) there are other conditions in the CONNECT BY clause, or
(c) you know what you are doing.
To help see why, run this query
SELECT SYS_CONNECT_BY_PATH (dname, '/') AS path
, LEVEL
FROM scott.dept
CONNECT BY LEVEL <= 3
;and study the results:
PATH LEVEL
/ACCOUNTING 1
/ACCOUNTING/ACCOUNTING 2
/ACCOUNTING/ACCOUNTING/ACCOUNTING 3
/ACCOUNTING/ACCOUNTING/RESEARCH 3
/ACCOUNTING/ACCOUNTING/SALES 3
/ACCOUNTING/ACCOUNTING/OPERATIONS 3
/ACCOUNTING/RESEARCH 2
/ACCOUNTING/RESEARCH/ACCOUNTING 3
/ACCOUNTING/RESEARCH/RESEARCH 3
/ACCOUNTING/RESEARCH/SALES 3
/ACCOUNTING/RESEARCH/OPERATIONS 3
/ACCOUNTING/SALES 2
/ACCOUNTING/SALES/ACCOUNTING 3
84 rows selected. -
Hi ,
Please help me on this…
Select * from EMP where Emp_Type in (1, 2 ) order by Emp_Type;
the above query gives me the result like this
Emp_Id Name Emp_Type
100 asas 1
101 dsds 1
122 gfgf 1
154 ytytyt 1
125 uyuy 1
153 reree 2
154 ytytt 2
600 trtrtr 2
700 gfghf 2
If I pass the Start with num 2 and give 3 as number of records to be displayed. I need to retrieve only the following rows..
Emp_Id Name Emp_Type
101 dsds 1
122 gfgf 1
154 ytytyt 1
154 ytytt 2
600 trtrtr 2
700 gfghf 2
If the Emp_Type was only one ie,
Select * from EMP where Emp_Type in (1) order by Emp_Type;
I know I can get it done by using TOP-N query method
select * from
(Select rownum RWnum ,A.* From
(Select * from EMP where Emp_Type in (1) order by Emp_Type) A
where rownum<=4)
where RWnum>=2;
but I am stuck up with doing for multiple Emp_Type..
here the Emp_Type could be more than two values…
Regards
Ben NarendranHi muthukumar S,dnikiforv,Vsugur
Thanks a lot for the analytical function ROW_NUMBER().
But still have some concern about the query you have given..
Let me first run the inner query.
SQL>
SQL > Select e.*,row_number() over(partition by Emp_Type order by Emp_Type) rno from
EMP e where Emp_Type in (1, 2 ) order by Emp_Type;
EMP_ID NAME EMP_TYPE RNO
154 aaa 1 1
101 dsds 1 2
122 gfgf 1 3
125 aaa 1 4
100 asas 1 5
700 gfghf 2 1
600 trtrtr 2 2
153 reree 2 3
If I give the range from 2 and 3 am suppose to get the following rows.
EMP_ID NAME EMP_TYPE RNO
101 dsds 1 2
122 gfgf 1 3
600 trtrtr 2 2
153 reree 2 3
when I run the query you sent am getting the following result..
SQL > select * from
(Select e.*,row_number() over(partition by Emp_Type order by Emp_Type) rno from
EMP e where Emp_Type in (1, 2 ) order by Emp_Type)
where rno between 2 and 3;
EMP_ID NAME EMP_TYPE RNO
101 dsds 1 2
154 aaa 1 3
600 trtrtr 2 2
700 gfghf 2 3
Here the company id 700 is not suppose to come, instead I have to get 153.
So I made some changes in the view and , wrote it like this
SQL> select * from
(select rno Rwnum,Outer_Qry.* from
(select Real_Qry.*,row_number() over(partition by emp_type order by emp_type)rno
from
(select emp_id,name,emp_type from emp where emp_type in (1,2) order by emp_type)Real_Qry)Outer_Qry
where rno <=3)
where Rwnum >=2;
RWNUM EMP_ID NAME EMP_TYPE RNO
2 101 dsds 1 2
3 122 gfgf 1 3
2 600 trtrtr 2 2
3 153 reree 2 3
I guess now am getting the correct result..
Please correct me if I am wrong, and please let me know if I have to make any modification on it..
Thanks and regards
Ben -
Hi... having problems with a query. Any assistance would be
much appreciated.
Two queries with identical columns: Villages_Query_1 and Villages_Query_2.
Both have these columns: Village_ID, Village_Name, Player_ID.
I need to find all records in Villages_Query_2 where the Village_ID's match but the Player_ID's have changed.
Example Village_Query_1
Village_ID
Village_Name
Player_ID
1
Houston
1
2
Dallas
2
3
Chicago
3
Example Village_Query_2
Village_ID
Village_Name
Player_ID
1
Houston
1
2
Phoenix
4
3
Chicago
3
4
New York
5
In this case, Village_ID = 2, has changed names (Dallas to Phoenix) and the Player_ID has changed (2 to 4). In addition, a new record was added.
The eventual output I need is to be able to report the following:
Player 2 village "Dallas" was taken by Player 4 and renamed "Phoenix".
New York is a new village owned by Player 5.
How the heck do I do this?? I have been trying query after query... reading about query of queries and JOINS and and and... I am now completely confused.
Help appreciated.
MarkWell... firstly... you do not use MS Access for that volume of data. Plain and simple. MS Access is for DBs like "My CD collection". It's a desktop application, and is not intended to be used other than as a desktop application.
Part of the reason for it not being appropriate for the job is that it can't do things like bulk loading data, which is kinda what you're wanting to do here. That aside, it's a single-user file-based DB which is simply not designed to work as the back-end for a web application (or any sort of serious application).
Anyway, I would approach this by putting all the data from the CSV files into the DB as is. Then on the DB run a query which gets all your changes. You're really going to struggle with the suggestions here to use valueList() to generate a list that is then used for a NOT IN(#list here#), because you're likely to have a mighty long list there. Even proper DBs like Oracle only allow 2000 entries in a list like that (SQL Server is about the same, from memory), so I doubt QoQ will allow even that. The reason the DBs put limits on these things is that doing a WHERE IN (#list#) is a really poorly-performing process.
If you've got all your data in the DB, then your query becomes pretty easy, and I'm sure even Access could cope with it. it'd be something like this:
SELECT VB.village_id, VB.village_name AS village_old_name, VB.player_id AS player_old_id,
VU.village_id AS village_new_id, VU.village_name AS village_new_name, VU.player_id as player_new_id
FROM villages_base VB
RIGHT OUTER JOIN villages_updates VU
ON VB.village_id = VU.village_id
WHERE VB.village_name != VU.village_name
(that's untested and I only gave it about 1min thought before typing it in, so don't quote me on that!)
Where VILLAGE_BASE is your original data, and VILLAGE_UPDATES is the data that indicates the changes. I'm kinda guessing that this is the sort of thing you want. Note: the "new" villages will be the ones which have NULLs for the village_id, village_old_name and player_old_id.
Getting all the data into the DB is going to be a matter of looping over the CSV file and doing an INSERT for each row. And that will take as long as it takes, so you might need to get some control over your request timeouts. However doing these inserts will take less time than all the QoQ logic suggested before, so you might be OK. And the query should be quick.
What happens to the data once the report is written? Does the "updated" data become the "live" data? If so, after you run your report you're gonna want to do something like a TRUNCATE on villages_base, and INSERT all the records from villages_update into it (then TRUNCATE villages_update, ready for the next time you need to run this process). Although don't take my word for it here, as I'm guessing your requirement here ;-)
Adam
Maybe you are looking for
-
I am using a MacBook Pro... late 2011. 8GB, 2.4 GHz... upgraded to OS X 10.10 I photo is 9.6... and says there is no current update available. I haven't tried too much, thinking that an update would be coming soon to address the current iPhoto issue
-
How to enforce save/open dialog on fileDownload
Dear All, in my adf bc app., an item is set to be displayed as fileDownload of OrdDocDomain to show a download link to the file stored in a orddoc column in a table. for doc file type, browser will prompt the dialog to ask to save or open, while for
-
"Importing Data to Form" results in nothing (Newbie)
Either I designed this form in Designer wrong, or there is some setting that is not allowing data to be saved even though it appears that I set it up correctly. I do have a Submit by E-mail button. I have e-mailed the form to 3 people (via the Initia
-
FLASH BUG?about value assignment is not same
HELP THANK YOU, ___y is -24.8 , after assignment to fallObj.y the fallObj.y is -24.75; oh my the Buddha!!!
-
Setting adobe indexes remotely as an admin
I have 10 index paths that I need to set up on potentially over 1,000 workstations, with varying versions of Adobe Acrobat Pro and Adobe Acrobat Reader. I need to automate this task, and do it remotely as a network admin. I know that the indexes ca