Query giving wrong result
Hi
Could anybody tell me why this query is giving the wrong result? The column 'Spend for Selected Period' is showing as far too much (ie exactly 11 times too much!!!) when totalling the 37 invoices involved
SELECT T0.[CardCode], T0.[CardName],T0.[MailCity] AS 'Town', T2.[SlpName] AS 'Rep',
SUM(T1.DocTotal - T1.VatSum) AS 'Spend for Selected Period', MAX(T3.CreateDate) AS 'Last Visit Date'
FROM OCRD T0 left JOIN OINV T1 ON T0.CardCode = T1.CardCode LEFT JOIN OSLP T2 ON T0.SlpCode = T2.SlpCode LEFT JOIN OSCL T3 ON T0.CardCode = T3.Customer
where T0.[CardCode] = 'wyk027/34' AND T1.DocDate BETWEEN '20090101' AND '20091231'
GROUP BY T0.[CardCode], T0.[CardName],T0.[MailCity], T2.[SlpName]
Thanks
Steve
Hi ,
It seems like it is duplicated by the number of service calls.
Try this one:
SELECT T0.CardCode, T0.CardName,T0.MailCity AS 'Town', T2.SlpName AS 'Rep',
SUM(T1.DocTotal - T1.VatSum) AS 'Spend for Selected Period', (select MAX(T3.CreateDate) from OSCL T3 where T0.CardCode = T3.Customer) AS 'Last Visit Date'
FROM OCRD T0 inner JOIN OINV T1 ON T0.CardCode = T1.CardCode inner JOIN OSLP T2 ON T0.SlpCode = T2.SlpCode
where T0.CardCode = '10001' AND T1.DocDate BETWEEN '20090101' AND '20091231'
GROUP BY T0.CardCode, T0.CardName,T0.MailCity, T2.SlpName
Best regards,
Maya
Similar Messages
-
Below is the query thats giving me wrong results ...can anyone help me figure where i am going wrong :(
SQL> select count(*) from t where source='LP1.1';
COUNT(*)
69
SQL> select count(*) from tblspring where line_a='LP1.1';
COUNT(*)
233now when i join these two table ...the total counts exceeds the expected records that i want
SQL> select count(*) from t , tblspring where t.source=tblspring.line_a and t.source='LP1.1';
COUNT(*)
16077the thing is i want to filter only those records from table t where the column named - source is equal to the column named line_a from table tblspring from the query in table t i get 69 records ....
now when i match the it table tblspring with the condition
i want the number of records should be less than or equal to 69 but not more than 69
Edited by: Suhail Faraaz on Mar 5, 2011 7:31 AM -
SQL Server 2012 Time(7) DataType values Comparison giving wrong result. Please help
We have a Table with StartTime and EndTime columns in Time(7) datatype, so we want to count the rows for each hour from 6 AM to 5 AM. If a record in table is as StartTime= 7 PM to EndTime = 5 AM (a shift of an employee) then the result is wrong beacause
being time(7) datatype the EndTime(5AM)< StartTime(7PM) in 24 hours format so following query gives wrong results.
select
* from EmpSchedule
where (StartTime>='19:00:00.0000000'
OR EndTime>='19:00:00.0000000')
Please help me out. ThanksDECLARE @clockIns TABLE (employeeID INT, startDateTime DATETIME, endDateTime DATETIME)
INSERT INTO @clockIns (employeeID, startDateTime, endDateTime)
VALUES
(1, '2014-07-01 19:01:00.000', '2014-07-02 04:27:00.000'),
(2, '2014-07-01 18:01:00.000', '2014-07-02 05:27:00.000'),
(3, '2014-07-01 19:01:00.000', '2014-07-02 05:27:00.000'),
(4, '2014-07-01 18:01:00.000', '2014-07-02 04:27:00.000')
SELECT *
FROM @clockIns
WHERE datepart(HOUR,startDateTime) BETWEEN 19 AND 23
OR datepart(HOUR,startDateTime) BETWEEN 0 AND 4
OR datepart(HOUR,endDateTime) BETWEEN 19 AND 23
OR datepart(HOUR,endDateTime) BETWEEN 0 AND 4
Try this out. -
Query giving wrong values in portal but correct through RSRT
Hi,
Users are running a query through portal which is giving wrong figures. But when we are running the query through RSRT it is showing correct values. The quesry is built on top of an InfoCube which is regularly updated and data in it is matching with R/3.
This is an Inventory Valuation Query.
Please suggest what could be the possible issue.
BR,
SayanHi,
Make sure cache is deleted for the particular query. While the report is executed through portal it refers the cache and if the data in the backend is not changed then the cache for a particular query selection is active and referred each time the query is run.
on other hand while running RSRT we have an option of not using cache and thus it refers the infoprovider and fetches the correct result. In this case cache could be invalid.
Try deleting the cache.
Regards,
Amit -
Query returning wrong results - Help required.
Hi All,
I am having a query in which I have 10 records, 5 with stop time 1 and 5 with stop time 2.
I have a scenario in which, I need to calculate the maximum,minimum for the records
with stop time 1 and 2.
What I did is, I selected all the 10 records using for loop. Within the loop
I am trying to find the maximum and minimum. It is giving me wrong results.
Please help me. My code is follows
declare
v_p1_min_stop_tm number;
v_p1_max_stop_tm number;
v_p2_min_stop_tm number;
v_p2_max_stop_tm number;
begin
for i in(
select
stop_tm
from
sample_stop
where
map_nbr = 16645 and
stop_dt = '05-sep-08'
)loop
if i.stop_tm = 1 then
select
min(i.stop_tm),
max(i.stop_tm)
into
v_p1_min_stop_tm,
v_p1_max_stop_tm
from
dual;
elsif i.stop_tm = 2 then
select
min(i.stop_tm),
max(i.stop_tm)
into
v_p2_min_stop_tm,
v_p2_max_stop_tm
from
dual;
end if;
end loop;
dbms_output.put_line('minimum p1 stop time : '|| v_p1_min_stop_tm);
dbms_output.put_line('maximum p1 stop time : '|| v_p1_max_stop_tm);
dbms_output.put_line('minimum p2 stop time : '|| v_p2_min_stop_tm);
dbms_output.put_line('maximum p2 stop time : '|| v_p2_max_stop_tm);
end;
My o/p is :
Minimum P1 stop time : 523
Maximum P1 stop time : 523
Minimum P2 stop time : 719
Maximum P2 stop time : 719
Here how can I make the data as two sets, one set with stop time 1 and
other with stop time 2.
Regards
RaghuIf the data type of stop_tm is varchar then try following
declare
v_p1_min_stop_tm number;
v_p1_max_stop_tm number;
v_p2_min_stop_tm number;
v_p2_max_stop_tm number;
begin
for i in(select stop_tm from sample_stop
where
map_nbr = 16645 and
stop_dt = '05-sep-08'
)loop
if i.stop_tm = 1 then
select min(to_number(i.stop_tm)), max(to_number(i.stop_tm))
into v_p1_min_stop_tm,v_p1_max_stop_tm
from
dual;
elsif i.stop_tm = 2 then
select
min(to_number(i.stop_tm)), max(to_number(i.stop_tm))
into
v_p2_min_stop_tm,v_p2_max_stop_tm
from
dual;
end if;
end loop;
dbms_output.put_line('minimum p1 stop time : '|| v_p1_min_stop_tm);
dbms_output.put_line('maximum p1 stop time : '|| v_p1_max_stop_tm);
dbms_output.put_line('minimum p2 stop time : '|| v_p2_min_stop_tm);
dbms_output.put_line('maximum p2 stop time : '|| v_p2_max_stop_tm);
end;
/ Regards
Singh -
Same query giving different results
Hi
I m surprised to see the behaviour of oracle. I have two different sessions for same scheema on same server. In both sessions same query returns different results. The query involves some calculations like sum and divisions on number field.
I have imported this data from another server using export / import utility available with 9i server. Before export every thing was going fine. Is there some problem with this utility.
I m using Developer 6i as the front end for my client server application. The behaviour of my application is very surprizing as once it shows the correct data and if I close the screen and reopen, it shows wrong data.
I m really stucked with the abnormal behaviour. Please tell me the possiblities and corrective action for these conditions.
Regards
Asad.There is nothing uncommitted in both the sessions. But still different results are returned.
I m sending u the exact query and result returned in both sessions.
Session 1:
SQL> rollback;
Rollback complete.
SQL> SELECT CC.CREDIT_HRS,GP.GRADE_PTS
2 FROM GRADE G, COURSE_CODE CC, GRADE_POLICY GP
3 WHERE G.COURSE_CDE=CC.COURSE_CDE
4 AND G.SELECTION_ID=45 AND G.GRADE_TYP=GP.GRADE_TYP
5 AND G.TERM_PROG_ID=17 AND GP.TERM_ID=14
6 /
CREDIT_HRS GRADE_PTS
3 4
4 3.33
4 3.33
3 4
3 4
3 4
3 4
7 rows selected.
SQL>
SESSION 2:
SQL> rollback;
Rollback complete.
SQL> SELECT CC.CREDIT_HRS,GP.GRADE_PTS
2 FROM GRADE G, COURSE_CODE CC, GRADE_POLICY GP
3 WHERE G.COURSE_CDE=CC.COURSE_CDE
4 AND G.SELECTION_ID=45 AND G.GRADE_TYP=GP.GRADE_TYP
5 AND G.TERM_PROG_ID=17 AND GP.TERM_ID=14
6 /
CREDIT_HRS GRADE_PTS
3 4
4 3.33
3 4
3 4
3 4
3 4
6 rows selected.
SQL>
U can see in session 1, seven rows are returned while in session 2 six rows are returned. I have issued a rollback before query to be sure that data in both sessions is same. -
Crystal XI R2 giving wrong result from a query...
I created a very simple query using 3 conditions with OR operator, looking for 3 columns within a date range. CR returns the results only for the first condition and ignores the 2 other conditions. I ran exactly the same query using the syntax from CR SQL in MS SQL Management Studio and it works fine there.
Here is the Record Selection syntax
{CONTACT2.UBATSENDDT} = {?Date} OR
{CONTACT2.UBWTSENDDT} = {?Date} OR
{CONTACT2.UBPTSENDDT} = {?Date}
Has anyone else experienced it too? Is there a trick to fix it? Please HELP....Thanks Jamie. That solved the problem. I've been using it for so long never knew about this setting. That's what happens when you learn things on your own. Appreciate your quick and right on the money response. Are there any other Report Options setting that should be turned on as a precaution?
Thanks Naga for suggestion but that wasn't the issue. I had already almost everything else.
Edited by: ManojT on Mar 2, 2012 8:51 AM -
Opening Illustrator 8 eps is giving wrong results
I have an eps (in Illustrator 8 format) where I manually changed the encoding to include east-european characters.
When I open this eps in the latest Illustrator version, I don't see those characters.
The attempts I made are:
in a TE block
39/quotesingle 96/grave 130/quotesinglbase/florin/quotedblbase/ellipsis
/dagger/daggerdbl/circumflex/perthousand/Scaron/guilsinglleft/OE 145/quoteleft
/quoteright/quotedblleft/quotedblright/bullet/endash/emdash/tilde/trademark
/scaron/guilsinglright/oe/dotlessi 159/Ydieresis /space 164/currency 166/brokenbar
168/dieresis/copyright/ordfeminine 172/logicalnot/hyphen/registered/macron/ring
/plusminus/twosuperior/threesuperior/acute/mu 183/periodcentered/cedilla
/onesuperior/ordmasculine 188/onequarter/onehalf/threequarters 192/Agrave
/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla/Egrave/Eacute
/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex/Idieresis/Eth/Ntilde
/Ograve/Oacute/Ocircumflex/Otilde/Odieresis/multiply/Oslash/Ugrave
/Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls/agrave/aacute
/acircumflex/atilde/adieresis/aring/ae/ccedilla/egrave/eacute/ecircumflex
/edieresis/igrave/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute
/ocircumflex/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex
/udieresis/yacute/thorn/ydieresis
TE
and further down: (128 80 \277) Tx
I tried to replace the Agrave with Lslash, but Illustrator seems to ignore that part when opening the eps, and still displays a À
Also tried with the TZ block to reencode the font:
%AI3_BeginEncoding: _Helvetica-Condensed-Bold Helvetica-Condensed-Bold
[ 191/Lslash /_Helvetica-Condensed-Bold/Helvetica-Condensed-Bold 0 0 1 TZ
%AI3_EndEncoding AdobeType
and further down: (128 80 \277) Tx
That change is also ignored by Illustrator.
The character is properly displayed when I open the eps and typing/pasting it in Illustrator, so I know the font supports it.
Am I doing something wrong here?
An alternate route could be to use the Illustrator SDK as platform for writing eps files, as I assume that the SDK properly supports unicode characters.
Did some research on that, but found that the SDK is only to make Illustrator plugins, and not supporting standalone applications, so, for automated eps generating it's not suitable.
Background:
I've created software which generates eps files with cartographic maps in them for publishing, printing or other purposes.
Recently, we got a new customer originating in eastern europe which wants their special, non-isolatin characters printed correcly.
Hope someone can give me any advice on how to proceed...
Greetings,
PaulI just realized that order by case x.rest rest isn't giving me 's','m','t','w','th','f','sh'
substring(Rest, 1, charindex('~', Rest+'~') - 1) is giving me 's','m','t','w','th','f','sh'
so I switched the order by to be
ORDER BY CASE substring(Rest, 1, charindex('~', Rest+'~') - 1) WHEN 'S' THEN 1 WHEN 'M' THEN 2 WHEN 'T' THEN 3 WHEN 'W' THEN 4
WHEN 'TH' THEN 5 WHEN 'F' THEN 6 WHEN 'SH' THEN 7 ELSE 8 END, x.FirstWord
That got the desired results.
Debra has a question -
Query returning wrong result set
I am running the following query on 8.1.7 database. The query is
SELECT Y.*, TEVStatus.lEndStatusFlag ENDSTATUSFLAG
FROM
(SELECT ROWNUM RANK, X.* FROM (SELECT lExceptionID ID,
TEVException.sMonitorName MONNAME, sExcpStatus STATUS
FROM TEVException WHERE (TEVException.lExceptionID IN
(SELECT lExceptionID FROM TEVException WHERE
sUserName_AssignedTo = 'vadmin')) ORDER BY
TEVException.lExceptionID DESC) X)
Y, TEVStatus WHERE (Y.RANK > 0 AND Y.RANK < 0 + 51 + 1) AND
(STATUS = TEVStatus.sStatusName);
The result is
RANK ID MONNAME STATUS ENDSTATUSFLAG
51 29 Type09B Open 0
50 30 Type09A Open 0
49 31 Type09E Open 0
48 32 Type09F Open 0
47 33 Type09G Open 0
46 34 Type09I Open 0
45 35 Type09C Open 0
44 36 Type10A Open 0
43 37 Type04A Open 0
39 41 Type08A Open 0
38 42 Type08C Open 0
RANK ID MONNAME STATUS ENDSTATUSFLAG
37 43 Type10B Open 0
36 44 Type10E Open 0
35 45 Type10C Open 0
34 46 Type10F Open 0
33 47 Type10D Open 0
32 48 Type08B Open 0
31 49 Type04B Open 0
29 51 Type08D Open 0
28 52 Type11E Open 0
27 53 Type11A Open 0
26 54 Type11D Open 0
RANK ID MONNAME STATUS ENDSTATUSFLAG
25 55 Type11C Open 0
24 56 Type11B Open 0
23 57 Type12A Open 0
22 58 Type12B Open 0
21 59 Type12C Open 0
20 60 Type12E Open 0
19 61 Type12A Open 0
18 62 Type12B Open 0
17 63 Type12E Open 0
16 64 Type12C Open 0
15 65 Type12D Open 0
RANK ID MONNAME STATUS ENDSTATUSFLAG
14 66 Type12D Open 0
4 80 Type01A_Ravi Open 0
3 83 Type01A_Ravi Open 0
2 84 Type01A_Ravi Open 0
1 87 Type01A_Ravi Open 0
42 38 Type06E Closed 8500
41 39 Type06A Closed 8500
40 40 Type06B Closed 8500
30 50 Type06C Closed 8500
13 68 Type01A Closed 8500
12 69 Type01A Closed 8500
RANK ID MONNAME STATUS ENDSTATUSFLAG
11 70 Type01A Closed 8500
10 71 Type01A Closed 8500
9 72 Type01A Closed 8500
8 73 Type01A Closed 8500
7 75 Type01A Closed 8500
6 77 Type01A Closed 8500
5 78 Type01A Closed 8500
51 rows selected.
In the above result, the RANK is not sorted properly and I
expected ID in descending order. The table which I was querying
had only about 100 records. I ran the same query on a larger
record set and the result is fine. I get ID in descending order
which I was expecting.
Could someone please tell me whether any bug in this case or
something wrong in the queryHi...
Took a quick look at tour SQL and....
SELECT Y.*
, TEVStatus.lEndStatusFlag ENDSTATUSFLAG
FROM ( SELECT ROWNUM RANK
, X.*
FROM ( SELECT lExceptionID ID
, TEVException.sMonitorName MONNAME
, sExcpStatus STATUS
FROM TEVException
WHERE ( TEVException.lExceptionID IN
( SELECT lExceptionID
FROM TEVException
WHERE sUserName_AssignedTo
= 'vadmin'
ORDER BY TEVException.lExceptionID DESC
) X
) Y
, TEVStat us
WHERE ( Y.RANK > 0
AND
Y.RANK < 0 + 51 + 1
AND STATUS = TEVStatus.sStatusName ;
Should "FROM ( SELECT ROWNUM RANK" be "FROM ( SELECT ROWNUM,
RANK"?
RANK is a reserved word, an analytic function.
Is "ORDER BY TEVException.lExceptionID DESC" doing anything? I
would drop it..
Hope this helps. Good Luck. -
Oralce query giving wrong data
Hi all oracle experts :
in oracle backend ( LOV ) user is selecting 'long text' instead of 'short text' and as a result user is getting wrong data Ship_To_Adress ( column ). here what i need is :
Upon data is coming from Long_Text table - it should not bring the wrong data Ship_To address.. It should give no value on the report.
feasibility of modifying query to maintain two Scenarios - Irrespective of Long or Short text - User should not give wrong 'Ship To' address on the pick ticket.
please go through the following query and make necessary changes. thanks in advance for your precious time valuable advice
looking the feasibility of modifying query to maintain two Scenarios - Irrespective of Long or Short text - User should not give wrong 'Ship To' address on the pick ticket.
Thanks in advance
Shiva
SELECT
wpsv.pick_slip_number "Pick Slip #",
wdd.source_header_number "Sales Order #" ,
wdd.source_line_number "Sales Order Line #" ,
nvl(round(ool.unit_selling_price,2),0) "unitsell price" ,
(nvl(round(ool.unit_selling_price,2),0))*nvl(wpsv.primary_qty,0) "Extended sell rice",
'*'||wpsv.transaction_id||'*' "Task ID" ,
wpsv.transaction_id "Task ID#" ,
msi.segment1 "Item",
msi.description "Item Description",
msi.segment1 || ' - ' ||msi.description "Item - Description",
wdd.requested_quantity_uom "UOM",
wdd.serial_number "Serial #",
wnd.delivery_id "Delivery#",
wpsv.from_subinventory "Pick from Sub-inventory",
wpsv.from_subinventory || ' - ' ||
SELECT
segment1||'.'||segment2||'.'||segment3||'.'||segment4
FROM
INV.MTL_ITEM_LOCATIONS
WHERE
inventory_location_id = DECODE(msi.reservable_type,2,wdd.locator_id,wpsv.from_locator_id)
) "Pick From",
SELECT
segment1||'.'||segment2||'.'||segment3||'.'||segment4
FROM
INV.MTL_ITEM_LOCATIONS
WHERE
inventory_location_id = DECODE(msi.reservable_type,2,wdd.locator_id,wpsv.from_locator_id)
) "Pick from Location",
wpsv.to_subinventory "Deliver to Sub-inventory",
select
segment1||'.'||segment2||'.'||segment3||'.'||segment4
from
inv.mtl_item_locations
where
inventory_location_id = wpsv.to_locator_id
) "Deliver to Location",
wpsv.primary_qty "Quantity to be Picked",
party.party_name||CHR(10)||
DECODE(ship_loc.address1, NULL, '',ship_loc.address1||CHR(10))||
DECODE(ship_loc.address2, NULL, '',ship_loc.address2||CHR(10))||
DECODE(ship_loc.address3, NULL, '',ship_loc.address3||CHR(10))||
DECODE(ship_loc.address4, NULL, '',ship_loc.address4||CHR(10))||
DECODE(ship_loc.city, NULL, NULL, ship_loc.city || ', ') || DECODE(ship_loc.state, NULL, NULL, ship_loc.state || ', ') || DECODE(ship_loc.postal_code, NULL, NULL, ship_loc.postal_code || ', ') || DECODE(ship_loc.country, NULL, NULL, ship_loc.country) SHIP_TO_ADDRESS,
NVL(h.shipping_instructions, '-') shipping_instructions,
NVL(h.shipment_priority_code,'-') shipment_priority_code,
NVL(OL.MEANING,'-') "Freight Terms",
NVL(FLV.meaning, '-') shipping_method,
NVL(QQA.quote_attachment, '-'),
RSA.name,
NVL(h.packing_instructions, '-') packing_instructions,
NVL(H.CUST_PO_NUMBER,'-') customer_po#
FROM
apps.oe_order_lines_all ool,
APPS.WSH_PICK_SLIP_V WPSV,
WSH.WSH_DELIVERY_DETAILS WDD,
INV.MTL_SYSTEM_ITEMS_B MSI,
WSH.WSH_DELIVERY_ASSIGNMENTS WDA,
WSH.WSH_NEW_DELIVERIES WND,
APPS.ORG_ORGANIZATION_DEFINITIONS ORG,
WMS.WMS_DISPATCHED_TASKS WDT,
APPS.OE_ORDER_HEADERS_ALL H,
APPS.HZ_CUST_SITE_USES_ALL SHIP_SU,
APPS.HZ_PARTY_SITES SHIP_PS,
APPS.HZ_LOCATIONS SHIP_LOC,
APPS.HZ_CUST_ACCT_SITES_ALL SHIP_CAS,
APPS.HZ_PARTIES PARTY,
APPS.FND_LOOKUP_VALUES FLV,
APPS.OE_LOOKUPS OL,
SELECT
OOH.header_id,
MAX(DECODE(rownum,1, FDST.short_text, ''))||CHR(10)||CHR(10)||MAX(DECODE(rownum,2, FDST.short_text, ''))||MAX(DECODE(rownum,3, FDST.short_text, ''))||CHR(10)||CHR(10)||MAX(DECODE(rownum,4, FDST.short_text, '')) quote_attachment
FROM
APPS.FND_ATTACHED_DOCUMENTS FAD
, APPS.FND_DOCUMENTS_TL FDT
, APPS.FND_DOCUMENTS_SHORT_TEXT FDST
, APPS.FND_DOCUMENTS FD
, APPS.FND_DOCUMENT_CATEGORIES_TL FDC
, APPS.OE_ORDER_HEADERS_ALL OOH
, APPS.ORG_ORGANIZATION_DEFINITIONS OOD
WHERE
OOD.organization_id =?Organization ? AND
OOH.ORDER_NUMBER = ?SO#? AND
OOH.org_id = OOD.operating_unit AND
TO_CHAR(OOH.header_id) = FAD.pk1_value AND
FAD.document_id = FDT.document_id AND
FAD.entity_name = 'OE_ORDER_HEADERS' AND
FDT.media_id = FDST.media_id AND
FDT.language = 'US' AND
FAD.document_id = FD.document_id AND
FD.category_id = FDC.category_id AND
FDC.language = 'US' AND
FDC.user_name ='APS_Pack/AR Invoice/CI/SO Ack Printing'
GROUP BY
OOH.header_id
) QQA
, APPS.RA_SALESREPS_ALL RSA
WHERE
wpsv.move_order_line_id =wdd.move_order_line_id AND
(wdd.source_header_number = ?SO#? ) AND
wdd.inventory_item_id = msi.inventory_item_id(+) AND
wdd.organization_id = msi.organization_id(+) AND
wdd.delivery_detail_id = wda.delivery_detail_id AND
wda.delivery_id = wnd.delivery_id(+) AND
wdd.organization_id = org.organization_id AND
wdt.TRANSACTION_TEMP_ID(+)=wpsv.transaction_id AND
wdt.organization_id (+) =?Organization ? AND
wdd.organization_id =?Organization ? AND
wdd.source_header_number = h.order_number AND
h.salesrep_id = RSA.salesrep_id(+) AND
h.org_id = RSA.org_id(+) AND
h.org_id = org.operating_unit AND
SHIP_PS.party_id = PARTY.party_id(+) AND
H.ship_to_org_id = SHIP_SU.site_use_id(+) AND
SHIP_SU.cust_acct_site_id = SHIP_CAS.cust_acct_site_id(+) AND
SHIP_CAS.party_site_id = SHIP_PS.party_site_id(+) AND
SHIP_LOC.location_id(+) = SHIP_PS.location_id AND
H.shipping_method_code = FLV.lookup_code(+) AND
FLV.lookup_type(+) = 'SHIP_METHOD' AND
FLV.language(+) = 'US' AND
QQA.header_id(+) = TO_CHAR(H.header_id) AND
wpsv.line_status = 'UNPICKED' AND
H.FREIGHT_TERMS_CODE=OL.LOOKUP_CODE(+)
AND OL.LOOKUP_TYPE(+) ='FREIGHT_TERMS' AND
OOL.header_id = wdd.source_header_id(+) AND
OOL.line_id = wdd.source_line_id(+) AND
EXISTS(
SELECT
'Y'
FROM
INV.MTL_ONHAND_QUANTITIES_DETAIL OHQ
WHERE
WDD.inventory_item_id = OHQ.inventory_item_id AND
WDD.organization_id = OHQ.organization_id AND
WPSV.from_subinventory = OHQ.subinventory_code
GROUP BY
'Y'
HAVING
SUM(transaction_quantity) >0
ORDER BY
2, 11, 12, 6, 3Thank you very much indeed for your reply - yes youre right. in oracle backend there are dropdown selections : 1) short text and 2) long text. as per the table user has to select short text so that he will get the correct output , but if by mistake user selects long text then the table is pulling wrong data. so here we need the query to be changed if user selects long text report shouldnt show any data..
i am not sure but as per my little knowledge in oracle i believe that the problem is lying in the folloiwng query line.. please help me out in this regard. i have a screen shots of oralce backend where user is selecting long text / short text but here theres no option of inserting the files...
DECODE(ship_loc.address1, NULL, '',ship_loc.address1||CHR(10))||
DECODE(ship_loc.address2, NULL, '',ship_loc.address2||CHR(10))||
DECODE(ship_loc.address3, NULL, '',ship_loc.address3||CHR(10))||
DECODE(ship_loc.address4, NULL, '',ship_loc.address4||CHR(10))||
DECODE(ship_loc.city, NULL, NULL, ship_loc.city || ', ') || DECODE(ship_loc.state, NULL, NULL, ship_loc.state || ', ') || DECODE(ship_loc.postal_code, NULL, NULL, ship_loc.postal_code || ', ') || DECODE(ship_loc.country, NULL, NULL, ship_loc.country) SHIP_TO_ADDRESS,
Thank you very much once again
Shiva -
Hello.
I have a query with LEFT OUTER JOIN that I think returns invalid results. Here are the problem details:
CREATE TABLE DOGERR(
IdDog INTEGER,
SfPdg CHAR(1),
IdVpl INTEGER,
SfVpGot INTEGER,
SfZrr CHAR(1)
INSERT INTO DOGERR(IdDog, SfPdg, IdVpl, SfVpGot, SfZrr) VALUES (1, 'S', 1, 1, '7');
INSERT INTO DOGERR(IdDog, SfPdg, IdVpl, SfVpGot, SfZrr) VALUES (2, 'S', 1, 1, '7');
INSERT INTO DOGERR(IdDog, SfPdg, IdVpl, SfVpGot, SfZrr) VALUES (3, '$', 1, 2, 'C');
COMMIT;
CREATE UNIQUE INDEX DOGERR_PK ON DOGERR(IdDog);
And now the query:
SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGotJoin, T.SfZrr AS SfZrrJoin
FROM DOGERR D
LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S' OR SfPdg = 'S') T ON
T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
WHERE
D.IdDog = 3
AND D.SfVpGot = 2
AND D.SfZrr = 'C';
This query should (by my understanding) return only one row in wich the joined subquery columns should be NULL. And indeed query returns only one row on Oracle Database 10g Release 10.2.0.1.0 - Production and on Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production:
IDDOG = 3, SFPDG = "$", IDVPL = 1, SFVPGOT = 2, SFZRR = "C", IDVPLJOIN = NULL, SFVPGOTJOIN = NULL, SFZRRJOIN = NULL
But on Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production it returns TWO rows:
IDDOG = 3, SFPDG = "$", IDVPL = 1, SFVPGOT = 2, SFZRR = "C", IDVPLJOIN = 1, SFVPGOTJOIN = 1, SFZRRJOIN = "7"
IDDOG = 3, SFPDG = "$", IDVPL = 1, SFVPGOT = 2, SFZRR = "C", IDVPLJOIN = 1, SFVPGOTJOIN = 1, SFZRRJOIN = "7"
And now the interesting part: any of the following modified versions of query works even on Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production, although modifications should not modify the result set:
-- Removed unnecessary WHERE conditions
SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGotJoin, T.SfZrr AS SfZrrJoin
FROM DOGERR D
LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S' OR SfPdg = 'S') T ON
T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
WHERE
D.IdDog = 3;
-- Removed unnecessary OR condition in subquery
SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGotJoin, T.SfZrr AS SfZrrJoin
FROM DOGERR D
LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S') T ON
T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
WHERE
D.IdDog = 3
AND D.SfVpGot = 2
AND D.SfZrr = 'C';
-- Removed columns from joined subquery from SELECT part
SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGotJoin
FROM DOGERR D
LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S' OR SfPdg = 'S') T ON
T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
WHERE
D.IdDog = 3
AND D.SfVpGot = 2
AND D.SfZrr = 'C';
NOTE: the query itself is a little stupid but this is just to demonstrate the problem. We have faced this problem at a customer with our real-world query.
So, my question is: why different results ?
Thanks.
Davidhi,
welcome to the forum,
don't have a solution, but I thought I'd let you know that the first SQL statement only returns 1 row on 10gR2
SQL> SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGo
tJoin, T.SfZrr AS SfZrrJoin
2 FROM DOGERR D
3 LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S' OR SfPdg = 'S') T ON
4 T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
5 WHERE
6 D.IdDog = 3
7 AND D.SfVpGot = 2
8 AND D.SfZrr = 'C';
IDDOG S IDVPL SFVPGOT S IDVPLJOIN SFVPGOTJOIN S
3 $ 1 2 C
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Solaris: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production -
Simple query returns wrong results in Sql 2012
On my Windows 8 box running Sql 2012 11.0.3128, this query returns an IncludeCount of 0 and an ExcludeCount of 1.
On my Windows 7 box running Sql 2008 10.50.2550 this query returns an IncludeCount of 3 and an ExcludeCount of 1, which is correct.
In short, it runs properly on these versions of OS and Sql's:
Windows 2008 R2 + Sql 10.50.2550
Windows 2008 R2 + Sql 10.50.4000
Windows 2012 SP1 + Sql 11.0.3000
Windows 7 + Sql 11.0.2100
And gives incorrect results on these OS's and Sql's (so far, tested):
Windows 8 Enterprise + Sql 11.0.3128
Windows 2008 R2 + Sql 10.50.2550
I wondered if anyone else can reproduce this? I can't figure out the magic combination of OS and SQL version this breaks on.
In all scenarios, the resulting @filters table is populated correctly, and the [Include] column is properly set to a 1 or a 0, so why aren't the other variables being properly set?
If I change the [ID] column to NONCLUSTERED, it works fine, too. It doesn't matter if @filters is a TVP or a temp table or an actual table, same (incorrect) results in each case.
DECLARE @filters TABLE([ID] bigint PRIMARY KEY, [Include] bit)
DECLARE @excludecount int = 0
DECLARE @includecount int = 0
DECLARE @id bigint
INSERT INTO @filters ([ID])
VALUES (1), (3), (4), (-7)
UPDATE @filters SET
@id = [ID],
@includecount = @includecount + (CASE WHEN @id > 0 THEN 1 ELSE 0 END),
@excludecount = @excludecount + (CASE WHEN @id < 0 THEN 1 ELSE 0 END),
[Include] = CASE WHEN @id > 0 THEN 1 ELSE 0 END,
[ID] = ABS(@id)
SELECT @includecount as IncludeCount, @excludecount as ExcludeCount
SELECT * FROM @filtersWhat part is undocumented?
http://technet.microsoft.com/en-us/library/ms177523.aspx
The above link states I can update variables inside an UPDATE statement ...
But it does not say what the correct result of what you are trying to would be. Variable assignment in UPDATE only makes sense if the UPDATE hits one row. If the UPDATE matches several rows, which value you the variable is set to is not defined.
It gets even more complicated when you have the variable on both sides of the expression. But I'd say that the only two values that makes as the final value of @includecount 0. An UPDATE statement, like other DML statements in SQL, is logically defined
as all-at-once. There are no intermediate results. Therefore the only possible values are the initial value of @includecount plus the value of the CASE statement, which always should returns 0, since @id is NULL when the UPDATE statement starts to execute.
I'm afraid that what you have is nonsense from a language perspective, and the result is undefined. Whenever you get different results from a query depending on whether you have certain indexes in place, you know that the query is indeterministic. There
are certainly part of SQL that are indeterministic, for instance ORDER BY on a non-unique columns. But in this particular case you have also wandered out into the land that is also undefined.
I'm not sure what you are trying to achieve, but I can only advice you to go back to the drawing board.
Erland Sommarskog, SQL Server MVP, [email protected] -
Query giving no result as well as no error
hi...good evening all...
i have a database server in a machine. the clients which are connected to those reported me that they cannot execute any queries from the schema connected to that database. i have tried and got the same result.
There was no error but the status was EXECUTING. a simple select count(1) from table name was executing through a huge time but giving no output.
i have bounced the database and after that it is working fine.
My question is...may I get any idea about why the database behaved like that??
please help.Hi,
Your DB Version ?
Secondly, if you checked the session_waits - then you might got some results/information with respect to session.
- Pavan Kumar N -
Link Verification program giving wrong results?
Hey all,
I wrote a simple link verification program which verifies dynamic links pulled from a database, but the results are not correct. Some valid links turned out to be marked as Error Links. Especially links to some of the pdf files. I am wondering why? Did anyone have similar problems?
Thank youCould be something wrong with your program. Or not. That's about all that can be said based on the information you gave.
-
I am trying to look for sub programs that use the synonyms in the schema.I wrote the following query.But its giving strange output.
select usy.synonym_name, us.text, us.name, us.type
from user_synonyms usy, user_source us
where upper(us.text) like ('%' || usy.synonym_name || '%')
and usy.synonym_name in
(select synonym_name
from user_synonyms us
where us.synonym_name <> us.table_name
and table_owner = 'XYZ')
order by usy.synonym_nameOutput
synonym_name text
txn_deposit select pir_detail_txn.instrument_amnt
I wonder why txn.instrument is taken same as txn_instrument which is the synonym name??where name like 'txn_instrument'
give all outputs like
txn_instrument
txn.instrument
txn1instrument
txn2instrument .......
but
where name like 'txn\_instrument' escape '\'
gives only txn_instrument
~Praveen
Maybe you are looking for
-
CALLING a STORED SQL FUNCTION from Java 1.1.8
I am trying to execute a stored function in JAVA 1.1.8, from an Oracle 8i Database. My stored function is simple, it converts an Input Number to an output TIME string. I am unsure how to code the call from Java. Are SQL STORED PROCEDURES treated the
-
Need a Statement of Volatility for HP Switch JE006A
Need a Statement of Volatility for HP Switch JE006A
-
Bugs in GPU renders in Premiere CC 2014
I have two UltraKey effects applied to a clip (one of them with a mask for special cleanup on a person's hair). With GPU turned on, in a rendered video, the person's hair has a flickering halo, like the second UltraKey is alternating between being on
-
Can't open attachments In gmail
gmail attachment is .jpg and will not display photo.
-
I need a SQL Query : Say I have a task created with TASK ID : 1 Then next record will be under it as : 1.1 When i am creating one more record I should get the Options as X_ 1.1.1 1.2 a) Say I have selected : 1.1.1