editing a start date of information from another table
Hello all;I have the sample data below
create table t1
(
id varchar2(200),
begin_date date,
ending_date date
);
create table t2
(
id varchar2(200),
period_number number(30),
period varchar2(200)
);
insert into t1
(id, begin_date, ending_date)
values
('A', sysdate, to_date('01/02/2020', 'MM/DD/YYYY'));
insert into t1
(id, begin_date, ending_date)
values
('B', sysdate, to_date('03/31/2011', 'MM/DD/YYYY') );
insert into t1
(id, begin_date, ending_date)
values
('C', sysdate, to_date('01/20/2011', 'MM/DD/YYYY'));
insert into t2
(id, period_number, period)
values
('A', 2, 'Years');
insert into t2
(id, period_number, period)
values
('B', 3, 'Months');
insert into t2
(id, period_number, period)
values
('C', 4, 'Days');
So what I'm trying to do is basically update the start date in t1, using the information from table t2for example, A
start date should be start date = 01/02/2020-2 years = 01/02/2018
for C
start date should be start date = 20/01/2011 - 4 = 01/16/2011
Thanks for the sample data, it makes life easier.
Something like this:
SQL> UPDATE t1
2 SET begin_date = (SELECT CASE WHEN t2.period = 'Years' THEN ADD_MONTHS(t1.ending_date, t2.period_number * -12)
3 WHEN t2.period = 'Months' THEN ADD_MONTHS(t1.ending_date, t2.period_number * -1)
4 ELSE t1.ending_date - t2.period_number END
5 FROM t2
6 WHERE t1.id = t2.id)
7 WHERE EXISTS (SELECT 1 FROM t2
8 WHERE t1.id = t2.id);
3 rows updated.
SQL> SELECT * FROM t1;
ID BEGIN_DATE ENDING_DATE
---------- ----------- -----------
A 02-JAN-2018 02-JAN-2020
B 31-DEC-2010 31-MAR-2011
C 16-JAN-2011 20-JAN-2011
If t2 is unique, you could also do it as an editable join view using a structure of similar cases.
John
Tags: Database
Similar Questions
-
How can I insert data from another table into a table containing a timestamp column
How you insert data from another table in a table if the target table contains a timestamp column. I tried to set the default value of GETDATE() column in the target table, but it does not work.
I use MS SQLSorry, I managed to get around this by inserting null as the value
-
Populating one table from another table
Hi Forum...
I'm trying to populate a table from another table using CFQUERY... I have no problem with the selection of data from the original table, but need help to get the data into the new table. I use MX 6.1 and access as the database server.
The two arrays have domain names identical to the same place, and I don't want to have to code all the column names in the selection and insert command. for example
< cfquery name = "GetData" datasource = 'somename' >
SELECT * FROM AssetTable1 WHERE BarCode = "123456".
< / cfquery >
< cfloop query = "GetData" >
< cfquery name = "InsData" datasource = 'somename' >
INSERT INTO AssetTable2 (xxxx...)
VALUES ("#xxxx... #'")
< / cfquery >
< / cfloop >
I hope this makes sense
Thanks in advance
DaveIf your tables are identical structures and their columns are of the same type and position, and both tables are in the same database, then put everything in a single query.
INSERT INTO AssetTable2
SELECT *.
OF AssetTable1
WHERE bar code = "123456".
If the columns were in different positions, then you should be listed explicitly in the INSERT and SELECT the parts, but you get the idea.
INSERT INTO table1 (col1, col2)
SELECT col1, col2
FROM table2
WHERE all that...Phil
-
Create a new table from another table which are ussing a stored procedure
Hello
I want to know if it is posibble to create a new table from another table which are ussing a stored procedure. This new table is created from another table that exists in the DB.
(in the following code the table tbl1 exist in the schema of the DB, but temp_tbl1 does not exist, it must be created by the procedure)
create or replace procedute temp is
temp_tbl1 tbl1% TYPE; the temp_tbl1 will have the same type of tbl1
Start
create the table temp_tbl1 as (select * from tbl1);
time of the end;
\
Thank you very much
Yes, it is possible to create a table using a procedure.
Do everything that use dynamic SQL isTry this:
==================================================
create or replace PROCEDURE Create Table as
BEGIN
EXECUTE IMMEDIATE ' CREATE TABLE testtable in select * from testingtable';
END createtable;
==================================================Kind regards
Ankur -
Select from another table, when the query returns no result
Hello
I have a question where I'm supposed to retrieve the address of an account id-based billing. However, the table of billing may not have an address. There is a table of addresses that always has an address for an account. If the billing address exists, it should be used, so I can't use the address table. Is it possible in a select statement to query to the billing address and if it does not exist, use the address table.
SELECT * FROM accounts a, b billings WHERE a.accountid = b.accountid
Any help will be greatly appreciated.
Thank you.user10407139 wrote:
HelloI have a question where I'm supposed to retrieve the address of an account id-based billing. However, the table of billing may not have an address. There is a table of addresses that always has an address for an account. If the billing address exists, it should be used, so I can't use the address table. Is it possible in a select statement to query to the billing address and if it does not exist, use the address table.
SELECT * FROM accounts a, b billings WHERE a.accountid = b.accountid
Any help will be greatly appreciated.
I think you need to explain more clearly if
-you only have a couple of "billing" columns which is empty and in this case, you want to use the columns from the table 'accounts '.
- or you have a join with another table that doesn't return data, for example a foreign key "address_id" "billing" is zero and therefore the join to other tables 'address' will return all the data
In the first case, you have already been provided with some examples here, how to use NVL or similar functions to achieve, even if the first post first evaluates the information of 'accounts' and if it is white using information from "billing". According to your description you need the other way around. The second post a subquery recursive useless in my opinion.
In the latter case, you should probably use an "outer" join so that the data in your table "bills" are returned, even if the join to another table is not at all the lines.
SELECT NVL(AD1.ADDRESS_ATTR1, AD2.ADDRESS_ATTR1) as ADDRESS_ATTR1, NVL(AD1.ADDRESS_ATTR2, AD2.ADDRESS_ATTR2) as ADDRESS_ATTR2, NVL(AD1.ADDRESS_STREET, AD2.ADDRESS_STREET) as ADDRESS_STREET, ... FROM accounts a INNER JOIN billings b ON a.accountid = b.accountid LEFT OUTER JOIN address ad1 ON b.address_id = ad1.address_id INNER JOIN address ad2 ON a.address_id = ad2.address_id;
In this way you pick up the address stored in the "invoices" table, if it existed, otherwise you pick up the address assigned to the "accounts" table I used an inner for the second address join join because you said that the account always has an assigned address.
Kind regards
RandolfOracle related blog stuff:
http://Oracle-Randolf.blogspot.com/SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676 /.
http://sourceforge.NET/projects/SQLT-pp/ -
Insert values from another table
Hello I have a table:
T1
---
ID
user
and another table:
T2
---
intellectual property
Mac
So I modified T1:
ALTER table T1 add ip number (20);
ALTER table T1 add mac number (20);
So I have:
T1
---
ID
user
intellectual property
Mac
T1 and T2 are the same number of lines.
Now, I want to insert the values of IP and mac of T2 in the fields ip address and mac of T1.
IP and mac of T2 fields can be "not null".
How can I do?
Thanks in advanceand what do you think about something like this:
UPDATE t1 SET t1.mac = (SELECT t2.mac FROM t2 WHERE t2.id = t1.id), t1.ip = (SELECT t2.ip FROM t2 WHERE t2.id = t1.id)
Give it a shot... validate the results before stolen.
HTH,
Thierry -
How to set the default on a table when data is inserted in another table
Hi all
I use Jdeveloper 11.1.1.2 and ADFBC.
I have two tables and tableA, tableB.
I wish that when I insert a line in tableA, automatically, a row is inserted in tableB.
How can I do? Creating a java class for tableA OS? How can I reference/create a line in the area of occurrence of another table?
Thank you
AndreaWhen you want that to happen... If you want to occur when you run the page, then have it in the getter()... If you like... When you set it... then's it in the Set accessor... You manually assign the id. or is he from any order?
-
update of data from another table
Hi, I would like to help. I Don t know how I can start doing:
I have a table with a column with numbers (primary key) and I need to create another column with the same values,
I want to change a table that has only numeric values (PK) to another
value, so I disable the constraints of linked tables
then I create another column that I called the "d" column and copy the values
from column A to column D
For example.
TABLE XYZ
COLUMN A: COLUMN D: (NEW)
00001 00001
00002-00002
00003-00003
00004 00004
Can I change the values in column A and D of the column will be kept
TABLE XYZ
COLUMN A: COLUMN D:
00001 99901
99902 00002
99903 00003
99904-00004
As the tables that must "point" to the column, I change the values with the new numbering
TABLE ZZZZ
COLUMN B: (the values of the column before the change)
00001
00002
00003
00004
...
I want it like this:
99901
99902
99903
99903
99904
...
In other words, I find the current value in column D of the XYZ table for the new value that is in column a.
I appreciate the help! :)Try this
Here you will find a record in test1 for a record for each line of teste2 in teste2 joined the condition t1.numer_documento2 = t2.numero_documento.This is called as subquery related Co. What you were doing was under queries that and not to join the top request.
UPDATE teste2 t2 SET NUMERO_DOCUMENTO = (SELECT T1.NUMERO_DOCUMENTO FROM teste1 t1 WHERE t1.numer_documento2 = t2.numero_documento and ROWNUM = 1 ) -- "Check/Select your data before you commit "
SS
-
read in select data from another table
Hello world.
IM Oracle11GR2 database.
I m facing the following problem:
I have 2 tables.
In the first picture, I have a few articles and 3 of these items then come.
(A) point Varchar2
(B) Item Varchar2.
(C) point digital and this point is the id of a record in the other table.
If the digital point > 0 then points A and B must be read in the second table
In the second table, I have 3 Articles.
(A) the id of the record.
B & C point are also point varchar2 and must be read in the first table, point C is > 0.
I'm looking for the way that when I write a normal selection in the first picture he gives me the point B & C of the second table if C point in the first table is > 0.
I thought to solve this problem with a trigger or something similar.
Any idea is welcome.
Regards to everyone.
You don't need a trigger for this. A simple select statement should do. Something like that? I got your if condition perfectly.
SELECT CASE WHEN (T1. C > 0) THEN (SELECT T2. B OF THE T2 WHERE T1. C = T2. (A) T1 OTHERWISE. END A,
BOX WHEN (T1. C > 0) THEN (SELECT T2. C FROM T2 WHERE T1. C = T2. (A) T1 OTHERWISE. B END HAVE B,
T1. C
FROM T1;
Look at the following example. Check if it fills your scenario.
-BEGINNING OF THE SAMPLE DATA
WITH T1 AS)
SELECT 'A' A, 'B' B, 1 C OF DOUBLE UNION ALL
SELECT 'C', ', 2 DOUBLE UNION ALL
SELECT 'DF', 'G', THE DOUBLE 0),
() AS T2
SELECT 1, 'X' B 'Y' C DOUBLE UNION ALL
SELECT 2, 'Z', 'BB' OF THE DOUBLE)
-END OF THE SAMPLE DATA
SELECT CASE WHEN (T1. C > 0) THEN (SELECT T2. B OF THE T2 WHERE T1. C = T2. (A) T1 OTHERWISE. END A,
BOX WHEN (T1. C > 0) THEN (SELECT T2. C FROM T2 WHERE T1. C = T2. (A) T1 OTHERWISE. B END HAVE B,
T1. C
FROM T1;
OUTPUT:
A B C
-- -- ----------
X Y 1 - since c > 0 A and B values in table 2 are replaced
Z BB 2 - since c > 0 A and B values in table 2 are replaced
DF G 0 - since c = 0, there is even value in table 1
Post edited by: Parth272025
-
How to publish a data in the table from another table
Oracle forms6i
Hai All
I created a form in order to generate traffic. I had a problem that I can post that two data
I have two tables, a table is created dynamically the data in the tables are extracted from the text file, and they are divided and stored fields are
Bartime Bardate barcode
000011 0815 01/08/2010 - it came
000012 0816 01/08/2010
000013 0815 01/08/2010
000011 1130 08/01/2010 - he goes for a break
000011 1145 01/08/2010 - it comes once again in
000011 1650 01/08/2010
000012 1655 01/08/2010
000013 1645 08/01/2010 - it home
That I need to transfer this data to the database table, the table name is dail_att and the fields are
Code bars, timein, timeout, breakin, escape, day like I need like this
Barcode Timein Breakin Breakout Timeout Attend_date
000011 0815 1130 1145 1650 01/08/2010
I tried to use some service number and rank of count, but it does not work Pls I give good solutions
The encoding is
declare
The CNT number;
bar_code varchar2 (25);
date of bar_date;
in_time varchar2 (25);
out_time varchar2 (25);
intr_intime varchar2 (25);
intr_outtime varchar2 (25);
Cursor c1 is
SELECT count (*), barcode, bardate, bartime
-ROW_NUMBER() over (order by bartime) RN
of temp_attendance
Group of barcodes, bardate, bartime
order by bardate;
Start
To r1 c1 loop
-Select the barcode, bardate, bartime
-ROW_NUMBER() on the partition by barcodeorder by bartime: nurse
-of temp_attendance
-the Group of barcodes, bardate, bartime
-order by bardate;
If (cnt < = 1) then
Select the code bar, intimate, intrtimein, introuttime, outtime, attend_date in bar_code, in_time, intr_intime, intr_outtime, out_time, bar_date from dail_att where attend_date = r1.bardate - 1;
Update dail_att set outtime = r1.bartime where attend_date = r1.bardate and barcode is r1.barcode.;
elsif (cnt < = 2) then
insert into dail_att(barcode,attend_date,intime,outtime)
values (R1. Barcode, R1.bardate, min (R1. Bartime), Max (R1. Bartime));
-other
-update dail_att set outtime = r1.bartime where attend_date = r1.bardate and barcode is r1.barcode.;
end if;
End loop;
forms_ddl ('commit');
exception
while others then
forms_ddl ('rollback');
message(SQLERRM|| dbms_error_Text);
message(SQLERRM|| dbms_error_Text);
End;
Thanks and greetings
Srikkanth.MYou seem to always have the same problem, but give it different titles. It would be much easier that you would hold a thread open until its resolved. The last time you had this problem that I posted the following code, it didn't help you? (Replace x and y in each if or ELSIF with the calendar you want to watch)
CURSOR cr IS SELECT CODE, DATE, TIME FROM FROM TEMP_ATTENDANCE ORDER BY CODE, DATE, TIME; BEGIN FOR rec IN cr LOOP IF rec.TIME BETWEEN x AND Y THEN -- Update record for last day .. ELSIF rec.TIME BETWEEN x AND Y THEN -- Update record .. ELSIF rec.TIME BETWEEN x AND Y THEN -- Update record .. ELSIF rec.TIME BETWEEN x AND Y THEN -- Update record .. ELSIF rec.TIME BETWEEN x AND Y THEN -- Update record .. ELSIF rec.TIME BETWEEN x AND Y THEN -- Update record .. END IF; END LOOP; END;
-
inserting data into a table from another table
Hello
I have a to insert a data in the other table.
My requirement is I field Date_effect_date in the departments, I would copy the details field in dept_effect_date of employees.
I used the query
Insert in the dept_effect_date of certain employees (dept_effect_date) departments;
and the result is:
SQL error: ORA-01400: cannot insert NULL into ('HR'. "'"' EMPLOYEES'."" EMPLOYEE_ID')
01400 00000 - "impossible to insert a NULL value in (%s)."
MY DB: oracle 10g XE
Sainaba
You can do this by UPDATE not INSERT.
Sudheeryekkala wrote:
Hello
I have a to insert a data in the other table.
My requirement is I field Date_effect_date in the departments, I would copy the details field in dept_effect_date of employees.
I used the query
Insert in the dept_effect_date of certain employees (dept_effect_date) departments;
and the result is:
SQL error: ORA-01400: cannot insert NULL into ('HR'. "'"' EMPLOYEES'."" EMPLOYEE_ID')
01400 00000 - "impossible to insert a NULL value in (%s)."
MY DB: oracle 10g XE
Sainaba
INSERT the results of will by adding new lines to the table so you have the above error. In your case, you must update the value of the existing column
(or, if the volume is large, then fill the data -
join the table two in a new table CREATE TABLE EMP_NEW AS SELECT * FROM EMPLOYEES, DEPARTMENTS
. fall of
; Rename emp_new to
; * constraints/indexes if necessary be supported...
)
E employees update
Set e.dept_effect_date = (select d.dept_effect_date
departments d
where e.dept_id = d.dept_id);
Concerning
Biju
-
Update the values in the Table from another Table containing historical data
So, I have two tables, a table and a master table. The current table is updated each week and at the end of the week, is copied to the main table to keep historical data. I have update the table in progress early in the week and want to take the latest data from the master table and update the current table with the data. The current table could have additional IDs or some of the IDS could have deposited (these lines would receive data in the main table). I want to only update the rows in the current table that have existing data to the attr1, attr2, attr3 columns. A particular ID may have more than one record in the primary table, I want only the last disk to use for updating the current table. The data from a different database where no direct connection is possible then I have to import data every week. Here are some statements of create/insert:
create table current_T (ID1 varchar(100),adate date,attr1 varchar(100),attr2 varchar(100),attr3 varchar(100))
create table Master_T (ID1 varchar(100),adate date,attr1 varchar(100),attr2 varchar(100),attr3 varchar(100))
begin insert into current_T (ID1,adate) values ('IE111','08/02/13'); insert into current_T (ID1,adate) values ('IE112','08/02/13'); insert into current_T (ID1,adate) values ('IE113','08/02/13'); insert into master_T (ID1,adate,attr1,attr2,attr3) values ('IE111','08/01/13','yes','abc','123'); insert into master_T (ID1,adate,attr1,attr2,attr3) values ('IE112','08/01/13','no','dgf','951'); insert into master_T (ID1,adate,attr1,attr2,attr3) values ('IE113','08/01/13','no','dgf','951'); insert into master_T (ID1,adate,attr1,attr2,attr3) values ('IE113','07/01/13','no','dgf','951'); end;
This has been a scratcher for me head and any help would be greatly appreciated. I'm coding in Apex 4.1
Thank you
-Steve
Not tested
merge into current_t c
using (select *)
Of
(select m.*
row_number() over (partition by m.id1 m.adate DESC order) rn
of master_t m
)
where rn = 1
) u
on (c.id1 = u.id1)
When matched then update
Set c.adate = u.adate
c.attr1 = u.attr1,
c.attr2 = u.attr2,
c.attr3 = u.attr3,
When not matched then insert
(c.id1, c.adate, c.attr1, c.attr2, c.attr3)
values
(u.id1, u.adate, u.attr1, u.attr2, u.attr3)
;
-
Can RoboHelp9 search for information from another database outside himself
Hi experts,
I just got the task of studying the search function of the RoboHelp if she could meet our needs:
We want to have a RoboHelp 9 to host the Center contact information, and we already have two or three other database exist for different departments that contact center agents could connect to search for information.
the question is:
1. is it possible, after RoboHelp 9 created and configured, agents can search and retrieve information not only reside in RoboHelp but is also in other databases?
2 is it possible that the public internet users could search for and retrieve information located in RoboHelp and other databases (allowing us to go)?
Thank you very much in advance,
Fran
Not sure you mean by your last paragraph - you can check the blog post described in the help article - http://iconlogic.blogs.com/weblog/2011/02/adobe-robohelp-9-external-content-search.html#tp
It is pretty cool (I don't use it myself in my projects because many of our customers are small internet); you could also add URLS to the search pages from external sites (such as a knowledge base) and let users make their own additional research.
-
update of column based on the sum of the data from another table
I have two tables:
Table1 (col1, col2, col3, col4, val1, status) Table2 (col1, col2, col3, col4, val2)
For Table1 and Table2, column (col1, col2, col3, col4) are the primary key of composit.
Table2 could have duplicated lines, that's why I want to group by (col1, col2, col3, col4) and sum (val2)
After that, I want to update Table1.val1 with the value of sum (Table1.val2) where Table1.col1 = Table2.col1 and Table1.col2 = Table2.col2 and Table1.col3 = Table2.col3 and Table1.col4 = Table2.col4 and status = 'V '.
I did something like this:
UPDATE Table1 SET val1 = (
WHERE Table1.col1 = t_sommevbrute.col1 and Table1.col2 = t_sommevbrute.col2 and Table1.col3 = t_sommevbrute.col3 and Table1.col4 = t_sommevbrute.col4)
Could someone help me please? Thank you
merge into table1 t1
using (select col1, col2, col3, col4, sum (val2) val2
from table2
Group
by col1, col2, col3, col4) t2
on (t1.col1 = t2.col1 t1.col2 = t2.col2 and t1.col3 = t2.col3 and t1.col4 = t2.col4 and)
When matched then
update set t1.val1 = t2.val2;
-
on average + get data from another table
Hello..
I have two tables:
user_table: contains (user_id, username)
rating_table: contains (rating_id, side, user_id)
I am trying to create a view of the note for users...
the notice must contain:
the id, user_name, the average of the coast
I created the following script:
Select a.user_id, b.username, AVG (a.rate_value)
rating_bookstore a, user_bookstore b
where a.user_id = b.user_id
A.user_id group;
but I got the following error message:
ORA-00979: not a GROUP BY expression
any help is appreciated...
Kind regards...10 x 2 wrote:
Hello..I have two tables:
user_table: contains (user_id, username)
rating_table: contains (rating_id, side, user_id)I am trying to create a view of the note for users...
the notice must contain:
the id, user_name, the average of the coastI created the following script:
Select a.user_id, b.username, AVG (a.rate_value)
rating_bookstore a, user_bookstore b
where a.user_id = b.user_id
A.user_id group;but I got the following error message:
ORA-00979: not a GROUP BY expressionany help is appreciated...
Kind regards...Select a.user_id, b.username, AVG (a.rate_value)
rating_bookstore a, user_bookstore b
where a.user_id = b.user_id
A.user_id group, b.username;
Maybe you are looking for
-
Satellite A40 graphics controller troble
HelloI have a Toshiba Satellite A40-261 (with Win_ XP Home sp2).I don't know why the GPA should be disabled when I try to update the intel Graphics Controller driver to the latest version.Does anyone know how I can solve my problem?Thank youDemetrio
-
Group residential zakljucavanje bezicnog Internet
Kako da zakljucam svoj internet bezicni da mi to nepovezuju tudji kompijuteri
-
Notebook HP 2000 - 2121TU: which RAM to buy?
I have this laptop HP 2000-2121TU running windows 8.1 update 1 32-bit. I want to improve my RAM. I've already posted a question about it & I got to know that this model can be upgraded to 8 GB max, but versions 32 bits can address up to 4GB of RAM. S
-
Configuration Cisco AP 2600 (AIR-CAP2602I-E-K9) and Cisco 2500 wireless controller?
This is the first time that I work with this type of devices (Cisco Ap 2600 (AIR-CAP2602I-E-K9) and wlc 2500)... my experience to the CCNP (router and Switch) How configuration Cisco Ap 2600 (AIR-CAP2602I-E-K9) and wlc 2500? Please find attachment (C
-
problem with sending mail after sending by GET
Hello. i've got such a problem-i can send a screenshot to the server by HTTP using the POST method like this: Bitmap _bitmap = new Bitmap(Display.getWidth(), Display.getHeight()); Display.screenshot(_bitmap); JPEGEncodedImage _jpg = JPEGEncodedImage.