I want to duplicate a table by changing the name of the duplicated table by adding today's date.
The date should be generated automatically (the day of the execution of the request)
Example :
Original Table Name = x
Duplicate Table Name = x_20221216 <-- today's date
create table x_20221216 as select * from x
Related
I have this access SQL append query where I have a Primary key set to now allow duplicates in the destination table. I'm confused if I am accomplishing the right thing here with the WHERE condition.
I am trying to only screen the newest records from the source table 'tbl_IMEI_MASTER' and only append(add) the records that do not have a match on the key in the destination table (same identifier as the source table). I think it's working but I did get a message that 72 rows (which is the total that were new and unique for the addition to the source table based on most recent date) were being updated in the destination table when only 14 of them should have been updated/added. Only 14 should have been identified as not having the same unique key.
INSERT INTO leads_historical (Customer, LeadNumber, ImportDate)
SELECT DISTINCT tbl_IMEI_MASTER.Customer, tbl_IMEI_MASTER.LeadNumber, tbl_IMEI_MASTER.ImportDate
FROM tbl_IMEI_MASTER
WHERE tbl_IMEI_MASTER.ImportDate = (SELECT MAX(tbl_IMEI_MASTER.ImportDate) FROM tbl_IMEI_MASTER);
I got it -
Using just select to break it down further I drilled down to the desired result.
SELECT DISTINCT tbl_IMEI_MASTER.Customer, tbl_IMEI_MASTER.LeadNumber, tbl_IMEI_MASTER.ImportDate
FROM tbl_IMEI_MASTER
WHERE tbl_IMEI_MASTER.ImportDate=(SELECT MAX(tbl_IMEI_MASTER.ImportDate) FROM tbl_IMEI_MASTER) AND NOT EXISTS (SELECT leads_historical.Customer FROM leads_historical WHERE leads_historical.Customer = tbl_IMEI_MASTER.Customer);
I'm trying to add a column called tstamp to a table that I've created. The column is to have the current timestamp in the format 'yyyy-MM-dd' populating each row.
I initially created the table from another table (table1) using the statement:
create location2.table2
as (select *
from location1.table1
);
I then used the alter table statement to add a field called tstamp to table2 using the code:
alter table location2.table2
add columns (tstamp date)
and I can see that this has successfully added a column to table2 named tstamp and populated each row of this table as null. I am now trying to insert the current date into every row in the field tstamp but am struggling to do so. I've tried using the insert into statement as:
insert into location2.table2 (tstamp)
values (to_date(current_timestamp()))
but get the error "Expression of type TOK_FUNCTION not supported in insert/values". I then also tried to add just a string and replaced the function with '2019-07-25'. Doing this added a new row to my table with null values in every column except tstamp which had a value '2019-07-25'. I'm now confused as it appears my approach was not the right one for the problem and am unsure where to go from here. Any help would be greatly appreciated.
create location2.table2 as (select current_date as tstamp,* from location1.table1 );
I have a table that contains one value, period_start TIMESTAMP NOT NULL. I'd like to have a second column that stores the day of that timestamp.
I tried the following sql:
ALTER TABLE foo ADD COLUMN day DATE;
UPDATE foo SET day = period_start::DATE;
ALTER TABLE foo ALTER COLUMN day SET NOT NULL;
Now, when I execute the above, I get an error that day contains null values. Looking at the content of the table, I see that every row has NULL as the value of day.
However, SELECT *, period_start::DATE FROM foo gives me the expected result.
Why does my UPDATE statement fail and how can I fix it so that the day column gets correctly populated?
For example I created a data of transactions and included names, location, and ID. Now I created another column saying date. How would I update each individually and include a date for each?
So this was my table before
and now this is my table after
How do I add information to the transaction date to lets say TransactionID 12?
update MSTransaction
set TransactionDate = ('2015-12-17')
where TransactionID = 12
This is the t-sql syntax
Update TableName set TransactionDate = DateTimeValue
Where TransactionID = 12
i have 2 table with four & five column in sql
in 1st table four column like ID - Parant - Position - Assign Id (ID+Position)
in 2nd table five column like assign ID - ID - L1- L2- L3
assign id & ID automatic update from 1st table
L1,L2,L3 based on assign id & ID column
i want a query for L1 column for update data like this procedure
find (ID+Left) in assign Id column and if match with records then copy record from ID column whose matched in assign Id and paste in L1 column
plz help me
You can use update with join to update table column.
Example: http://sqlfiddle.com/#!2/07622