Simple Query Failure? from 2 tables: pull First [DATE] Where [OIL] 0
I am a novice Access 2010 user, and I do not know how to write VBA code. I have written many queries, some built upon others and packaged them into macros, but that's about the extent of my experience, to date.
My problem. I built a query from 2 tables: [AC_PROPERTY] and [AC_PRODUCT]
I have linked the tables by PROPNUM. Designed the query to give me every PROPNUM in the db, then give me the 'First' [DATE] 'Where' [OIL] is >0.
When I run the query with 1 PROPNUM qualified, it works brilliant. Every case I check is working, on a one-PROPNUM-at-a-time basis. As soon as I remove the PROPNUM from criteria, so it will pull all PROPNUMs in the db, it appear to work -- that
is, until you check the data.
For some reason, it's not consistently picking the correct First date where Oil >0. I cannot figure out why it's working on some and not on others. I thought it was a date format problem, but haven't been able to determine or solve the issue.
I have always (historically) figured out my query problems, but this one has me stumped! Help!?
thank you :-)
I have linked the tables by PROPNUM. Designed the query to give me every PROPNUM in the db, then give me the 'First' [DATE] 'Where' [OIL] is >0.
The problem is that FIRST will not always give you the oldest date. Access uses FIRST to get the first record it finds, not the earliest date.
Use MIN to find oldest date.
Build a little, test a little
Similar Messages
-
How to make a table of annual data from a table of quarterly data?
I've got a table of quarterly data. I'd like to create a table of annual data, where each cell has the sum of the four cells for the four quarters that make up a calendar year.
I can do this by pasting a formula into every 4th cell of a second column, but I'd really like a way that doesn't require so many paste operations. Also, when I try doing the same thing into a column that doesn't leave three blank cells, I don't get the annual totals I want (the totaling just moves down one cell, rather than four).
Two related questions:
Is there anyway to move my data so that the four quarters appear side-by-side in 4 columns? (Then the annualizing would be easy.)
Is there any way to take every 4th element from a column and put it somewhere?pmbrewer
I'm having trouble picturing what you have. Correct me if I'm wrong, but I see a single column blocked off in groups of 4 cells. You don't mention them, but you must have additional columns with some sort of identifiers including quarter numbers and items? With this picture in mind let's go to your questions.
pmbrewer wrote:
I've got a table of quarterly data. I'd like to create a table of annual data, where each cell has the sum of the four cells for the four quarters that make up a calendar year.
I can do this by pasting a formula into every 4th cell of a second column, but I'd really like a way that doesn't require so many paste operations.
This can be done but you're right, it's awkward and can be handled better as you suggest in the first question below.
Also, when I try doing the same thing into a column that doesn't leave three blank cells, I don't get the annual totals I want (the totaling just moves down one cell, rather than four).
Can you explain this more clearly? Perhaps give an example?
Two related questions:
Is there anyway to move my data so that the four quarters appear side-by-side in 4 columns? (Then the annualizing would be easy.)
This can be done and you're right, it's easier. How much data has to be moved?
Is there any way to take every 4th element from a column and put it somewhere?
What do you mean by this?
I'm sure members of the forum will be able to help you with a better understanding of your problem. Ultimately I see a table looking something like below:
pw -
How to compare two rows from two table with different data
how to compare two rows from two table with different data
e.g.
Table 1
ID DESC
1 aaa
2 bbb
3 ccc
Table 2
ID DESC
1 aaa
2 xxx
3 ccc
Result
2Create
table tab1(ID
int ,DE char(10))
Create
table tab2(ID
int ,DE char(10))
Insert
into tab1 Values
(1,'aaa')
Insert
into tab1 Values
(2,'bbb')
Insert
into tab1 Values(3,'ccc')
Insert
into tab1 Values(4,'dfe')
Insert
into tab2 Values
(1,'aaa')
Insert
into tab2 Values
(2,'xx')
Insert
into tab2 Values(3,'ccc')
Insert
into tab2 Values(6,'wdr')
SELECT
tab1.ID,tab2.ID
As T2 from tab1
FULL
join tab2 on tab1.ID
= tab2.ID
WHERE
BINARY_CHECKSUM(tab1.ID,tab1.DE)
<> BINARY_CHECKSUM(tab2.ID,tab2.DE)
OR tab1.ID
IS NULL
OR
tab2.ID IS
NULL
ID column considered as a primary Key
Apart from different record,Above query populate missing record in both tables.
Result Set
ID ID
2 2
4 NULL
NULL 6
ganeshk -
How to select data from a table using a date field in the where condition?
How to select data from a table using a date field in the where condition?
For eg:
data itab like equk occurs 0 with header line.
select * from equk into table itab where werks = 'C001'
and bdatu = '31129999'.
thanks.Hi Ramesh,
Specify the date format as YYYYMMDD in where condition.
Dates are internally stored in SAP as YYYYMMDD only.
Change your date format in WHERE condition as follows.
data itab like equk occurs 0 with header line.
select * from equk into table itab where werks = 'C001'
and bdatu = <b>'99991231'.</b>
I doubt check your data base table EQUK on this date for the existince of data.
Otherwise, just change the conidition on BDATU like below to see all entries prior to this date.
data itab like equk occurs 0 with header line.
select * from equk into table itab where werks = 'C001'
and <b> bdatu <= '99991231'.</b>
Thanks,
Vinay
Thanks,
Vinay -
Simple Query in Oracle Linked Table in MS Access causes full table scan.
I am running a very simple query in MS ACCESS to a linked Oracle table as follows:
Select *
From EXPRESS_SERVICE_EVENTS --(the linked table name refers to EXPRESS.SERVICE_EVENTS)
Where performed > MyDate()
or
Select *
From EXPRESS_SERVICE_EVENTS --(the linked table name refers to EXPRESS.SERVICE_EVENTS)
Where performed > [Forms]![MyForm]![Date1]
We have over 50 machines and this query runs fine on over half of these, using an Oracle Index on the "performed" field. Running exactly the same thing on the other machines causes a full table scan, therefore ignoring the Index (all machines access the same Access DB).
Strangely, if we write the query as follows:
Select *
From EXPRESS_SERVICE_EVENTS
Where performed > #09/04/2009 08:00#
it works fast everywhere!
Any help on this 'phenominon' would be appreciated.
Things we've done:
Checked regional settings, ODBC driver settings, MS Access settings (as in Tools->Options), we have the latest XP and Office service packs, and re-linked all Access Tables on both the slow and fast machines independantly).Primarily, thanks gdarling for your reply. This solved our problem.
Just a small note to those who may be using this thread.
Although this might not be the reason, my PC had Oracle 9iR2 installed with Administratiev Tools, where user machines had the same thing installed but using Runtime Installation. For some reason, my PC did not have 'bind date' etc. as an option in the workarounds, but user machines did have this workaround option. Strangely, although I did not have the option, my (ODBC) query was running as expected, but user queries were not.
When we set the workaround checkbox accordingly, the queries then run as expected (fast).
Once again,
Thanks -
Selecting from Multiple Tables but requiring data to match from a 3rd table
Hello Everyone,
I'm having alot of trouble with this select
I have three tables:
prod_poured, conc_test, and cyl_breakTo put together my report, I need to grab this data:
cyl_break.pour_no "Pour Number", cyl_break.cyl_id "Cylinder ID", cyl_break.pour_d "Pour Date", conc_test.mix "Mix #", conc_test.amb_t "Ambient Temperature", conc_test.conc_t "Concrete Temperature", conc_test.air "Air %", cyl_break.break_d "Break Date", cyl_break.age "Age (Days)", cyl_break.spec_str "Specified Strength", cyl_break.str "Specimen Strength"and I need it to grab all data in those two tables when one column in the prod_poured table meets a certain condition
This is what I have so far:
select cyl_break.pour_no "Pour Number", cyl_break.cyl_id "Cylinder ID", cyl_break.pour_d "Pour Date", conc_test.mix "Mix #", conc_test.amb_t "Ambient Temperature", conc_test.conc_t "Concrete Temperature", conc_test.air "Air %", cyl_break.break_d "Break Date", cyl_break.age "Age (Days)", cyl_break.spec_str "Specified Strength", cyl_break.str "Specimen Strength"
from conc_test inner join cyl_break on conc_test.pour_no = cyl_break.pour_no, prod_poured
where conc_test.pour_no = prod_poured.test_id and prod_poured.job_no = '9-12-821';It gives me the right results but wayyy too many of them so obviously I've got something wrong.
the results it gives are this:
Pour Number Cylinder ID Pour Date Mix # Ambient Temperature Concrete Temperature Air % Break Date Age (Days) Specified Strength Specimen Strength
100322A 100322A3 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.6
100322A 100322A3 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.6
100322A 100322A3 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.6
100322A 100322A3 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.6
100322A 100322A3 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.6
100322A 100322A3 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.6
100322A 100322A3 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.6
100322A 100322A3 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.6
100322A 100322A3 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.6
100322A 100322A4 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.4
100322A 100322A4 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.4
100322A 100322A4 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.4
100322A 100322A4 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.4
100322A 100322A4 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.4
100322A 100322A4 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.4
100322A 100322A4 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.4
100322A 100322A4 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.4
100322A 100322A4 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.4
100324A 100324A3 24-MAR-10 10 9 15 5.8 21-APR-10 28 35 51.9
100324A 100324A3 24-MAR-10 10 9 15 5.8 21-APR-10 28 35 51.9
100324A 100324A3 24-MAR-10 10 9 15 5.8 21-APR-10 28 35 51.9
100324A 100324A3 24-MAR-10 10 9 15 5.8 21-APR-10 28 35 51.9
100324A 100324A4 24-MAR-10 10 9 15 5.8 21-APR-10 28 35 50.8
100324A 100324A4 24-MAR-10 10 9 15 5.8 21-APR-10 28 35 50.8
100324A 100324A4 24-MAR-10 10 9 15 5.8 21-APR-10 28 35 50.8
100324A 100324A4 24-MAR-10 10 9 15 5.8 21-APR-10 28 35 50.8
100326B 100326B3 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 48.3
100326B 100326B3 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 48.3
100326B 100326B3 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 48.3
100326B 100326B3 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 48.3
100326B 100326B3 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 48.3
100326B 100326B3 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 48.3
100326B 100326B3 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 48.3
100326B 100326B3 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 48.3
100326B 100326B3 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 48.3
100326B 100326B3 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 48.3
100326B 100326B3 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 48.3
100326B 100326B3 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 48.3
100326B 100326B3 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 48.3
100326B 100326B3 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 48.3
100326B 100326B4 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 49
100326B 100326B4 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 49
100326B 100326B4 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 49
100326B 100326B4 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 49
100326B 100326B4 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 49
100326B 100326B4 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 49
100326B 100326B4 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 49
100326B 100326B4 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 49
100326B 100326B4 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 49
100326B 100326B4 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 49
100326B 100326B4 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 49
100326B 100326B4 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 49
100326B 100326B4 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 49
100326B 100326B4 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 49
100324E 100324E3 24-MAR-10 10 10 15 6 21-APR-10 28 35 50.7
100324E 100324E3 24-MAR-10 10 10 15 6 21-APR-10 28 35 50.7
100324E 100324E3 24-MAR-10 10 10 15 6 21-APR-10 28 35 50.7
100324E 100324E3 24-MAR-10 10 10 15 6 21-APR-10 28 35 50.7
100324E 100324E3 24-MAR-10 10 10 15 6 21-APR-10 28 35 50.7
100324E 100324E4 24-MAR-10 10 10 15 6 21-APR-10 28 35 51.6
100324E 100324E4 24-MAR-10 10 10 15 6 21-APR-10 28 35 51.6
100324E 100324E4 24-MAR-10 10 10 15 6 21-APR-10 28 35 51.6
100324E 100324E4 24-MAR-10 10 10 15 6 21-APR-10 28 35 51.6
100324E 100324E4 24-MAR-10 10 10 15 6 21-APR-10 28 35 51.6The results I need it to give are this:
100322A 100322A3 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.6
100322A 100322A4 22-MAR-10 10 16 16 4.2 19-APR-10 28 35 50.4
100324A 100324A3 24-MAR-10 10 9 15 5.8 21-APR-10 28 35 51.9
100324A 100324A4 24-MAR-10 10 9 15 5.8 21-APR-10 28 35 50.8
100324E 100324E3 24-MAR-10 10 10 15 6 21-APR-10 28 35 50.7
100324E 100324E4 24-MAR-10 10 10 15 6 21-APR-10 28 35 51.6
100326B 100326B3 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 48.3
100326B 100326B4 26-MAR-10 10 9 15 5.7 23-APR-10 28 35 49As you can see my query provides the right results, just way too many of them. I only need to have one result per cylinder id.
I can't seem to wrap my mind around this one and if somebody could put together a proper select based on what I need that would be extremely helpful. If you need any more data to provide help just ask and I'll paste it.
Thanks,
dtr
Edited by: dtr on Apr 26, 2010 11:12 AMdtr wrote:
Hi,
Here are the create table statements:
create table conc_test
(p_date date, job_no varchar, mix varchar, pour_no varchar, amb_t varchar, conc_t varchar, slump varchar, air varchar, density varchar, cyl_cast_time timestamp)
create table cyl_break
(job_no varchar, pour_no varchar, cyl_id varchar, pour_d varchar, break_d varchar, age varchar, spec_str varchar, str varchar, mix);
create table prod_poured
(prod_id varchar, pour_id varchar, test_id varchar);
Great!
Don't forget to post the INSERT statements, and the output from that data (if it is different from what you posted in your first message).
Basically I need to pull the data I showed above out of conc_test and cyl_break, but only data that has the proper job_number which is retrieved from the prod_poured table. The prod_poured test_id for everything that has the proper prod_poured job_no So an IN-subquery, like Sudhakar and I suggested, should work.
What was the problem when you tried them? Post the query you ran, even if you just copied and pasted it from this thread: there may have be an editing error.
prod_poured test_id is the same thing as conc_test pour_no and cyl_break pour_noExactly! But that doesn't answer the question: Is that value unique in all the tables? If not, in which tables can it be duplicated? -
Data from 3 tables having latest dates
Hi,
Need some help with PL/SQL code, I need to write a code which will get data from 3 tables all with the latest date.
For a particular ACT_CODE the output of the SQL query should show data having the latest dates from 3 tables, if there is no
date in the table, it should show the remaining data (think left join will do the trick here)
Table Names:
Institution_UPDT aiu
ASQ_CONTACT ac
GR_AUTHORIZE gr
All 3 tables have ACT_Code as common
Column Names
INSTITUTION_UPDT aiu -- aiu.ACT_CODE,aiu.project_id as proj,aiu.UPDT_TYPE_ID, aiu.USER_ID, aiu.UPDT_DATE
ASQ_CONTACT ac -- ac.ACT_CODE as contact_code,ac.project_id,ac.first_name, ac.middle_initial,ac.last_
name,ac.title,ac.status,ac.status_date
GR_AUTHORIZE gr --gr.ACT_CODE as grad_code,gr.name, gr.title AS grad_title, gr.submit_date
The date column names are
ac.status_date,
aiu.UPDT_DATE and
gr.submit_date
Thank you everyone
appreciate your help
JeshHi, Jesh,
user11095252 wrote:
That is correct, I want to include all the columns from ASQ_Contacts, Institution_UPDT and GR_AUTHORIZEOh! You want all columns from all three tables, not just ASQ_Contacts. That changes the problem considerably!
UNION requires that all prongs have the same number of columns, and that the datatypes of the columns match. That's no problem if we just need act_code and a date from each one. If we just need additional columns from one table, it's easy to add literal NULLs to the other prongs to serve as the additional columns. But if we need all (or even several) columns from all three tables, that's no good. So let's revert to your original idea: outer joins.
I want to display only one row which has the latest date with the most recently updated time (example:mm/dd/yyyy hr:min:sec am/pm)Yes, but what if there is a tie for the most recently updated time?
In case of a tie, the query below will pick one of the contenders arbitrarily. That may be fine with you (e.g., you may have UNIQUE constraints, making ties impossible). If you need a tie-breaker, yiou can add more columns to the analytic ORDER BY clauses.
WITH aiu AS
SELECT institution_updt.* -- or list columns wanted
, ROW_NUMBER () OVER ( PARTITION BY act_code
ORDER BY updt_date DESC
) AS r_num
FROM institution_updt
WHERE act_code = :p1_act_code
AND project_id = :p2_project_id
, ac AS
SELECT asq_contact.* -- or list columns wanted
, ROW_NUMBER () OVER ( PARTITION BY act_code
ORDER BY status_date DESC
) AS r_num
FROM asq_contact
WHERE act_code = :p1_act_code
AND project_id = :p2_project_id
, gr AS
SELECT gr_authorize.* -- or list columns wanted
, ROW_NUMBER () OVER ( PARTITION BY act_code
ORDER BY submit_date DESC
) AS r_num
FROM gr_authorize
WHERE act_code = :p1_act_code
SELECT * -- or list columns wanted
FROM aiu
FULL OUTER JOIN ac ON ac.act_code = aiu.act_code
AND ac.r_num = 1
AND aiu.r_num = 1
FULL OUTER JOIN gr ON gr.act_code = NVL (ac.act_code, aiu_act_code)
AND gr.r_num = 1
;That's a lot of code, so there may be typos. If you'd post CREATE TABLE and INSERT statements for a few rows of sample data, I could test it.
In all places where I said "SELECT *" above, you may want to list the individual columns you want.
If you do that in the sub-queries, then you don't have to qualify the names with the table name: that's only required when saying "SELECT *" with another column (r_num, in this case).
It's more likely that you won't want to say "SELECT *" in the main query. The three r_num columns, while essential to the query, are completely useless to your readers, and you might prefer to have just one act_code column, since it will be the same for all tables that have it. But since it may be NULL in any of the tables, you'll have to SELECT it like this:
SELECT COALESCE ( aiu.act_code
, ac.act_code
, gr_act_code
) AS act_codeThe query above will actually work for multiple act_codes. You can change the condidition to something like
WHERE act_code IN (&act_code_list)If so, remember to change it in all three sub-queries. -
Select from 4 tables but include data from 3 even if 4th is null
Hello -
I'm quite new to oracle and apex, but enjoying learning - but sometimes I need a gentle nudge to know what I need to learn about.
I have a select statement that works - selecting specific columns from 3 tables:
SELECT
"TERRITORIES"."TER_NAME" "TER_NAME",
"TERRITORY_TYPES"."TTP_DESCRIPTION" "TTP_DESCRIPTION",
"COUNTRIES"."CNT_DESCRIPTION" "COUNTRY"
FROM
"TERRITORIES", "TERRITORY_TYPES","COUNTRIES"
WHERE
"TERRITORIES"."TER_TTP_ID"="TERRITORY_TYPES"."TTP_ID"
and
"COUNTRIES"."CNT_TER_ID"="TERRITORIES"."TER_ID"
I want to add in a 4th table for, you guessed it, States.
However, many of the countries do not yet have states in the states table (and may never have any). Therefore, they do not appear in the results. I want them included in the query, so that I'll have the opportunity to add in the data via Apex.
Is there a phrase I can insert in the 1st query so that I'll get data for Territory Type, Territory and Country, even if the State table is null?
Or, do I need to insert records into the state table, such as: insert into states (state_ID, STATE_CNT_ID) values (state_seq.nextval,2). If so, do I just do that over and over, replacing the value? Or is this where I need to learn about bind variables? Or some other command?
Thank you-
Marion in NY
Edited by: mtpaper on Oct 24, 2009 12:54 PM
I FIGURED IT OUT! I DID IT! How do I mark myself as helpful???
insert INTO states
(state_ID, STATE_CNT_ID)
SELECT state_seq.nextval, cnt_id
FROM countries
WHERE not exists (select * from states where states.state_cnt_id = countries.cnt_id)
Edited by: mtpaper on Oct 24, 2009 1:10 PMYou certainly could insert data into the STATES table, but I generally wouldn't advise inserting rows into a STATES table for states that don't actually exist. It would seem to make far more sense to just do an outer join when you include the STATES table in your query
SELECT "TERRITORIES"."TER_NAME" "TER_NAME",
"TERRITORY_TYPES"."TTP_DESCRIPTION" "TTP_DESCRIPTION",
"COUNTRIES"."CNT_DESCRIPTION" "COUNTRY",
s.state_name
FROM TERRITORIES t ,
TERRITORY_TYPES tt,
COUNTRIES c,
states s
WHERE "TERRITORIES"."TER_TTP_ID"="TERRITORY_TYPES"."TTP_ID"
and "COUNTRIES"."CNT_TER_ID"="TERRITORIES"."TER_ID"
and c.cnt_id = s.state_cnt_id(+)The {noformat}(+){noformat} operator indicates that you want to do an outer join. So if there is no row in the STATES table that matches the join condition, a NULL is returned.
From a purely stylistic standpoint, I would generally suggest using aliases (i.e. the T, TT, C, and S in the FROM clause) rather than having to constantly write out all the table names. And I wouldn't suggest putting double-quotes around everything-- that forces all your identifiers to be upper case and case sensitive.
Justin -
Hi There,
In SAP GRC 10.0, our team had an issue where we could not add duplicate fields from separate table (see ERROR: Select Currency/UoM field for the selected analyzed fields). This was resolved by the SAP Note 1904313/ 1904314 (http://service.sap.com/sap/support/notes/1904313).
We upgraded our system to SAP GRC 10.1 SP05 and could now add the duplicate fields from separate tables. SAP Note 1904313/ 1904314 was part of SAP GRC 10.1 SP03 so it makes sense that we, in a higher version (SP05), would be able to do this.
The issue now is when we add the duplicate fields from different tables and run the Ad-hoc Query to test if the data source works correctly, the No Data Selected warning persists. This means that the data source provides no data for analysis, which is required to write our business rules.
Below is an example:
Basic data source with just one currency reference field EBAN-WAERS.
When you run the Ad-Hoc Query you receive data.
Basic data source with second currency reference field EKKO-WAERS.
When you run the Ad-Hoc Query no data is found.
Please also make reference to the following thread logged by my colleague (ERROR: Select Currency/UoM field for the selected analyzed fields)
Any assistance to receive data with duplicate fields from separate tables will be highly appreciated.
Thanking you in advance.
Regards
Gary KhanHi
following are the error messages from dump
hrtText
There is already a line with the same key.
hat happened?
Error in ABAP application program.
The current ABAP program "SAPLCKMS" had to be terminated because one of the
statements could not be executed.
This is probably due to an error in the ABAP program.
rror analysis
You wanted to add an entry to table "\FUNCTION-POOL=CKMS\DATA=T_DYN_CKMLCR",
which you declared
with a UNIQUE KEY. However, there was already an entry with the
same key.
This may have been in an INSERT or MOVE statement, or within a
SELECT ... INTO statement.
In particular, you cannot insert more than one initial line into a
table with a unique key using the INSERT INITIAL LINE... statement.
rigger Location of Runtime Error
Program SAPLCKMS
Include LCKMSF01
Row 226
Module type (FORM)
Module Name DYNAMIC_PERIOD_CLOSING
Source code where dump ocured
222
223 APPEND ht_ckmlpp TO t_add_ckmlpp.
224 APPEND LINES OF ht_ckmlcr TO t_add_ckmlcr.
225 INSERT ht_ckmlpp INTO TABLE t_dyn_ckmlpp.
>>>> INSERT LINES OF ht_ckmlcr INTO TABLE t_dyn_ckmlcr.
227 ENDWHILE.
Also I guess there is problem with material ledger in R/3 side
I have never worked on material ledger before so dont hav idea of Tcode and tables in SAP R/3 for material ledger.
Thanks
Navneet -
Need to fetch value from a table based on data range
Hello there,
I was hoping that the community could give me a hand with this little puzzle I got.
I am currently creating a Time Dimension for a data wharehouse, and I have the requirement to populate a column named SEASON (e.g: Summer, Winter, Spring, Autumn) for each date row. So for the 20/Dec/2013, the Season column must say Winter.
Here is now my Time Dimension table looks like, without the Season information (which I yet have to load):
DimTime Table
TIMEID
FULLDATE
YEAR
SEASON
MONTH
MONTHDAY
WEEK
WEEKDAY
274
02-MAR-10
2010
3
2
9
2
275
03-MAR-10
2010
3
3
9
3
276
04-MAR-10
2010
3
4
9
4
277
05-MAR-10
2010
3
5
9
5
278
06-MAR-10
2010
3
6
9
6
279
07-MAR-10
2010
3
7
9
7
This entire table is being populated using Oracle functions to manipulate a date field from another table, named PDATE:
My ETL Code
INSERT INTO DimTime(timeid, fulldate, year, month, monthday, week, weekday)
SELECT tim_seq.NEXTVAL, pdate, year, month, monthday, week, weekday
FROM (SELECT DISTINCT pdate, EXTRACT(year from pdate) year, EXTRACT(month from pdate) month,
EXTRACT(day FROM pdate) monthday, to_number(to_char(to_date(pdate,'DD/MM/YY'),'IW')) week,
TO_CHAR(pdate, 'D') weekday
FROM Performance PER
ORDER BY pdate);
NOTE: Code considers the table DimTime to be truncated every time it loads (i.e.: I don't need to consider additional loads).
As you can see, Season wasn't populated. Since the solstices and equinoxes vary for each year, I can't just say that Summer start at a given date (e.g: 21 of June) because one year it could be the 19/Jun, another the 22/Jun, etc. So in order to solve this problem, I have a table named Season which defines the START and END dates for the seasons:
Season Table
SEASON#
SEASONNAME
YEAR
DATEFROM
DATETO
1
Spring
2010
01-MAR-10
30-MAY-10
2
Summer
2010
31-MAY-10
29-AUG-10
3
Autumn
2010
30-AUG-10
28-NOV-10
4
Winter
2010
29-NOV-10
27-FEB-11
5
Spring
2011
28-FEB-11
29-MAY-11
6
Summer
2011
30-MAY-11
28-AUG-11
7
Autumn
2011
29-AUG-11
27-NOV-11
8
Winter
2011
28-NOV-11
26-FEB-12
9
Winter
2009
30-NOV-09
28-FEB-10
This is the bit I don't know how to do. How can I make sure that I populate the correct Season in my DimTime table based on the season specified in the Season table?
Thanks in advance for your help!
Regards,
P.Just join to table Season:
INSERT
INTO DimTime(
timeid,
fulldate,
year,
month,
monthday,
week,
weekday,
seasonname
SELECT tim_seq.NEXTVAL,
pdate,
year,
month,
monthday,
week,
weekday
FROM (
SELECT DISTINCT pdate,
EXTRACT(year from pdate) year,
EXTRACT(month from pdate) month,
EXTRACT(day FROM pdate) monthday,
to_number(to_char(to_date(pdate,'DD/MM/YY'),'IW')) week,
TO_CHAR(pdate,'D') weekday,
seasonname
FROM Performance PER,
season
WHERE pdate between datefrom and dateto
SY. -
How do you Select data from two tables with similar data amd merge the output together.
I have two Tables containing Sales Data. I want to read the Table a sort by date and accumulate dollars by order date. Then I want to read the second table and accumulate these dollar amounts by date and then merge the records together so that I gave 1 row
with amounts for type A and amounts for type b.
Here are the tables I am looking at.
Select Cast(J.Order_Date As Varchar(11))) As [Order Date]
,Sum(Case when Sales_Code like '%Comm%' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Comm]
,Sum(Case when Sales_Code = '5-Day' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
,Sum(Case when Sales_Code like '%Auto%" then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
,Sum(Case when Sales_Code = '' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Fixed]
,Sum(Case when Sales_Code = 'XX' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Comm)
,Sum(Case when Sales_Code = 'YY' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Auto)
,Sum(Case when Sales_Code = 'ZZ' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Fixed)
from [PRODUCTION].dbo.Job As J
union all
Select Cast(SH.Order_Date As Varchar(11))) As [Order Date]
,Sum(Case when Sales_Code like '%Comm%' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Comm]
,Sum(Case when Sales_Code = '5-Day' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
,Sum(Case when Sales_Code like '%Auto%" then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
,Sum(Case when Sales_Code = '' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Fixed]
,Sum(Case when Sales_Code = 'XX' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Comm)
,Sum(Case when Sales_Code = 'YY' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Auto)
,Sum(Case when Sales_Code = 'ZZ' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Fixed)
from [PRODUCTION].dbo.SO_Detail As SD
Inner Join [PRODUCTION].dbo.SO_Header As SH
on SD.Sales_Order = SH.Sales_Order
Group by J.Order_Date
Order by J.Order_Date Desc
Looking for output like
Order Date Job Comm Job AUto Job Fixed SO Comm SO AUto SO Fixed
Mar-11-2014 100.00 250.00 50.00 200.00 300.00 400.00
Mar-10-2014 500.00 340.00 0.00 110.00 400.00 500.00
Mar-09-2014 600.00 333.00 56.00 210.00 500.00 300.00
Thanks for your help
SWProductionSeeing the output it looks like what you need is this
select COALESCE(p.[Order Date],q.[Order Date]) AS [Order Date],
COALESCE([Job Comm],0) AS [Job Comm],
COALESCE([Job AUto],0) AS [Job AUto],COALESCE([Job Fixed],0) AS [Job Fixed],COALESCE([SO Comm],0) AS [SO Comm],COALESCE([SO AUto],0) AS [SO AUto],COALESCE([SO Fixed],0) AS [SO Fixed]
from
Select Cast(J.Order_Date As Varchar(11))) As [Order Date]
,Sum(Case when Sales_Code like '%Comm%' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Comm]
,Sum(Case when Sales_Code = '5-Day' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
,Sum(Case when Sales_Code like '%Auto%" then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
,Sum(Case when Sales_Code = '' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Fixed]
,Sum(Case when Sales_Code = 'XX' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Comm)
,Sum(Case when Sales_Code = 'YY' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Auto)
,Sum(Case when Sales_Code = 'ZZ' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Fixed)
from [PRODUCTION].dbo.Job As J
)p
full join
Select Cast(SH.Order_Date As Varchar(11))) As [Order Date]
,Sum(Case when Sales_Code like '%Comm%' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Comm]
,Sum(Case when Sales_Code = '5-Day' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
,Sum(Case when Sales_Code like '%Auto%" then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
,Sum(Case when Sales_Code = '' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Fixed]
,Sum(Case when Sales_Code = 'XX' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Comm)
,Sum(Case when Sales_Code = 'YY' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Auto)
,Sum(Case when Sales_Code = 'ZZ' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Fixed)
from [PRODUCTION].dbo.SO_Detail As SD
Inner Join [PRODUCTION].dbo.SO_Header As SH
on SD.Sales_Order = SH.Sales_Order
Group by J.Order_Date
)q
on p.[Order Date] = q.[Order Date]
Order by COALESCE(p.[Order Date],q.[Order Date]) Desc
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Query help from multiple tables
I want a query from these kind of data placed in 3 different tables.
case_batch = 2677101 , which has fine_no = 2012,2013,2014. fine_amt = 150,425,75.
fine can be paid in cash,check or Credit card(CC)
tble 1
seq --- case_batch
1 --- 2677101
tble two
seq -- case_batch -- fine_no -- fine_amt
1 -- 2677101 -- 2012 -- 150
2 -- 2677101 -- 2013 -- 425
3 -- 2677101 -- 2014 -- 75
tble three
seq -- fine_no -- cash -- check -- CC
1 -- 2012 ---- 50 -- 0 -- 0
2 -- 2012 ---- 0 -- 50 -- 0
3 -- 2012 ---- 0 -- 0 -- 50
4 -- 2013 ---- 25 -- 0 -- 0
5 -- 2013 ---- 0 -- 0 -- 400
6 -- 2014 ---- 0 -- 0 -- 75
I am looking for a result query like this
case_number -- fine_no fine_amt cash check cc
2677101 --- 2012 --- 150 --- 50 --- 50 --- 50
--- 2013 --- 425 --- 25 --- 0 ---400
--- 2014 --- 75 --- 0 --- 0 ----75
2677102 etc
hopes i made my request clear.
appreciate all help.
Edited by: pl/sql baby on Apr 28, 2009 10:49 AM
Edited by: pl/sql baby on Apr 28, 2009 10:58 AMwith t2 as (
select 1 seq,2677101 case_batch,2012 fine_no,150 fine_amt from dual union all
select 2 seq,2677101 case_batch,2013 fine_no,425 fine_amt from dual union all
select 3 seq,2677101 case_batch,2014 fine_no,75 fine_amt from dual union all
select 4 seq,2677102 case_batch,2015 fine_no,150 fine_amt from dual union all
select 5 seq,2677102 case_batch,2016 fine_no,425 fine_amt from dual union all
select 6 seq,2677102 case_batch,2017 fine_no,75 fine_amt from dual
t3 as (
select 1 seq,2012 fine_no,50 cash,0 check_,0 CC from dual union all
select 2 seq,2012 fine_no,0 cash,50 check_,0 CC from dual union all
select 3 seq,2012 fine_no,0 cash,0 check_,50 CC from dual union all
select 4 seq,2013 fine_no,25 cash,0 check_,0 CC from dual union all
select 5 seq,2013 fine_no,0 cash,0 check_,400 CC from dual union all
select 6 seq,2014 fine_no,0 cash,0 check_,75 CC from dual union all
select 7 seq,2015 fine_no,50 cash,0 check_,0 CC from dual union all
select 8 seq,2015 fine_no,0 cash,50 check_,0 CC from dual union all
select 9 seq,2015 fine_no,0 cash,0 check_,50 CC from dual union all
select 10 seq,2016 fine_no,25 cash,0 check_,0 CC from dual union all
select 11 seq,2016 fine_no,0 cash,0 check_,400 CC from dual union all
select 12 seq,2017 fine_no,0 cash,0 check_,75 CC from dual
select case t2.fine_no when min(t2.fine_no) over(partition by t2.case_batch) then t2.case_batch end case_batch,
t2.fine_no,
t2.fine_amt,
sum(cash) cash,
sum(check_) check_,
sum(CC) CC
from t2,
t3
where t3.fine_no = t2.fine_no
group by t2.case_batch,
t2.fine_no,
t2.fine_amt
order by t2.case_batch,
t2.fine_no
CASE_BATCH FINE_NO FINE_AMT CASH CHECK_ CC
2677101 2012 150 50 50 50
2013 425 25 0 400
2014 75 0 0 75
2677102 2015 150 50 50 50
2016 425 25 0 400
2017 75 0 0 75
6 rows selected.
SQL> SY. -
Deleting Query Elements From Backend Tables
Hi All,
i have made some changes to a CKF and executed the report. It got executed but when i reopened the query i am not able to expand the RKF n CKFs on the left side. Whenever i tried to expand them the query designer is exiting.
I tried deleting the query element which i modified from the backend tables using RSZDELETE but i am not able to do so as this CKF is being used in 2 more RKFs.
Could you please let me know how to delete a query element which is reusable from the backend.
Regards,
MKHi Satyam,
I deleted the Query which was containing the CKF and RKF that i changed earlier. when i tried to delete these 2 by kFs in RSZDELETE i am not able to delete them.
Scenario 1:
when i tried to delete the CKF 1 ..the system is displaying msg tht this is being used in RKF 1.
when i tried to delete the RKF1..then system is displaying msg tht this is being used in CKF 1.
i mean there is a circular reference which has happened b/w these two KFs.
Could you let me know how to get rid of it as i am not able to open the Query in Bex nor in RSRT.
Regards,
MK -
How merge query results from joined table into one additional column
<code>
Here is example
TABLE A:
id | value
1 | a
2 | a
3 | b
TABLE B
id | id_in_table_a | value
1 | 1 | d
2 | 1 | e
3 | 2 | g
</code>
this select should get all columns from table A where value = 'a' and all values related to this record from B merged to one column separated for example with pipe, so the output should looks like this
<code>
id | value | merged_column
1 | a | d|e
2 | a | g
</code>
thanks for helpIf you are on 10g, you can use this:
SQL> create table a
2 as
3 select 1 id, 'a' value from dual union all
4 select 2, 'a' from dual union all
5 select 3, 'b' from dual
6 /
Tabel is aangemaakt.
SQL> create table b
2 as
3 select 1 id, 1 id_in_table_a, 'd' value from dual union all
4 select 2, 1, 'e' from dual union all
5 select 3, 2, 'g' from dual
6 /
Tabel is aangemaakt.
SQL> select id
2 , value
3 , rtrim(v,'|') merged_column
4 from ( select id
5 , value
6 , v
7 , rn
8 from a
9 , b
10 where a.id = b.id_in_table_a
11 model
12 partition by (a.id)
13 dimension by (row_number() over (partition by a.id order by b.id) rn)
14 measures (a.value, cast(b.value as varchar2(20)) v)
15 rules
16 ( v[any] order by rn desc = v[cv()] || '|' || v[cv()+1]
17 )
18 )
19 where rn = 1
20 /
ID VALUE MERGED_COLUMN
1 a d|e
2 a g
2 rijen zijn geselecteerd.Regards,
Rob. -
SQL Query Report from DB2 Tables
Team,
Our HTML DB application requires us to build a Report against a DB2 table. In addition, we are required to view the detail of the selected DB2 data on a second page, much like the 2 page report as generated by the wizard.
So...what is the best way to present DB2 data in both Report and Detail format using HTML DB? Better yet...how can DB2 tables be set up/connected/defined to HTML DB so they operate just like the Oracle tables which reside inside the Oracle database?
Thanks for your help.
HowardAn addendum to my original post....
How about the use of a JDBC driver? Is there one available to meet my requirements?
Thanks again
Howard
Maybe you are looking for
-
Problem with pictures in iPhoto '09 on a Mac
After a recent download of travel pictures numbering over 1,000, every so often a few pictures will split and have normal color on half but the other half is very light. Sometimes when these thumbnails are opened the color is just fine but I end up
-
[Resolved][ODQ] Error Running Exported Batch Script Outside of ODI
Dear ODI experts, I have Installed 10.1.3.4.0 ---> selected "Oracle Data Integrator, Oracle Data Profiling, Oracle Data Quality 10.1.3.4.0" ---> Complete (1012MB) - follow all steps of "Design a Name and Address Cleansing Project" section in Sample T
-
Settings Mail Autocheck replaced by Settings Fetch New Data on 3g?
Hi, I was wondering if anyone can confirm that the 3g iPhone no longer has the "Auto-Check" function listed in Settings>Mail (above the Show, Preview etc fields; I don't see "Auto-Check" here like some user guides I have seen have indicated). Assumin
-
Is Belkin TuneDok Zen Touch compatible with MICRO Z
TUNEDOK ZEN TOUCH Is compatible with MICRO ZEN? Any product similiar compatible with Micro Zen? (((thnxs, sorry by my english, i'm spanish)))
-
My Photoshop elements 11 and 13 organizer suddenly exits. photoshop elements is not responding. Message occurs when the error is found. solicit help, That's all.