Insert into a backup table based on date [closed] - sql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
My table in Oracle 11g has 6 fields. I also have a backup table also with no values. The original table has 2 date values. I need to insert into the backup table from the original table the orders having an order-date 5 months back as of today.
The table has a field names ORDER-DATE and has records entered inside.

insert into backup_table
select * from original_table
where order-data > add_months(sysdate,-5);

Related

POSTGRESQL: Insert Data from another table [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
In above table customer ids are listed what I want to do is to get those ids from this table,
create another table named PROMOTION CLASSES where PREMIUM, PLUS AND NORMAL are in columns and put first 100 ids under PREMIUM COLUMN and soon.
Please help.
This creates you table with classification
CREATE TABLE promotion_classes as
SELECT customer_id,
case when customer_id < 100 then
'PREMIUM'
else
'NORMAL'
END as CLASSES
FROM CUSTOMER_TBL

How to find records 2 years from a created date stored in the individual record [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Need help in writing an MS SQL query to delete all data in a table, 2 years or more from when it was originally added. created_date is stored as datetime field type.
Table: users
user_id
user_name
created_date
Try this
DELETE FROM <your_table> WHERE created_date < DATEADD('yy', -2, getdate())
SELECT *
FROM [database].[dbo].[users] where created_date < DATEADD(year,-2,GETDATE())

How to update a table from one database to another? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have two database like A and B and a common table as TBL where the table TBL from A database has 1555 rows but the table TBL from database has only 1000 rows. I need to update the TBL in B database from A database.
1.How can I do it if these A and B database on same server name
2.what if these both database are on different server names .
Thanks in advance
INSERT INTO YourDbToBeInsertedInto..YourTable
SELECT *
FROM YourDbToBeInsertedFrom..YourTable
WHERE PrimaryKey NOT IN (SELECT PrimaryKey
FROM YourDbToBeInsertedInto..YourTable)
Use linked servers

Subtract two column values and store result in another column [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have the one table eg tbl_1 and i have column eg A B C. When I insert into column A and B its result store into C like c=a-b.
If you wish to create virtual/computed columns while creating a table structure, Since you dint specified which RDBMS you are using, please following links (the one that suits you) :
Hope it helps you.
MYSQL
ORACLE 11G
SQL SERVER
CREATE TABLE tbl_1
(
A int,
B int,
C AS A - B
);

Overwriting Values From SQL Table to Another SQL Table [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have 2 databases, a live and backup. I want to overwrite the the values in a specific field in the live database from those that are in the backup. The database structure is identical the only difference is there name.
How do I do this?
Try this
UPDATE liveDB
SET column2 = src.column2 -----Whichever column you want
FROM BackupDB.dbo.Table1 AS src
INNER JOIN LiveDB.dbo.Table1 AS dest
ON src.column1 = dest.column1;
Updated
UPDATE live
SET l.ola_m_1= b.ola_m_1
FROM live.dbo.order_line l
JOIN backup.dbo.order_line b
ON --Whatever is Similar column between two