Copy/Insert a new record in a database

Overkill32

New Member
Joined
May 13, 2011
Messages
49
I'm trying to insert a new record in a database that is basically the last one i entered. Put in another way, if there was no data available for today for the item XYZ, i would need to take the data entered yesterday at 17h (there is a column in the database for the time and one for the date) and create a new record identical to it for today and change the time. Can anyone help me with the basic structure the code would have to take either in VBA or SQL? I will need to automate this process...
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
I don't follow why you must have a record for today --- if there is no data, seems like there is NO data. Why create an artificial record???
 
Upvote 0
I need to have a price that reflects an "it didnt change" status. The price that i need to copy is therefore the last one i had yesterday. This is the methodology i need to follow for that database.
 
Upvote 0
Something along these lines should do the job

Code:
INSERT INTO YourTable(fld1,fld2,fld3,fldx)
SELECT fld1,fld2,fld3,fldx FROM YourTble 
Where Item = "the item you are dealing with"  AND
TheDate = (SELECT max(theDate) from yourTable )


theDate represents the column Name of the date_field.
item = "XYZ" for example.

If there is a different Price for each Item, then you'd have to put this in some loop construct.
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,547
Members
452,925
Latest member
duyvmex

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top