Hi all i have been struggling this for a while now! I have some data files with a date in them, these are dumped into a staging table. What i would like my script/function to do is to read the date for each record in the staging table and move to the appropriate table. Now i know i could do this very easily just using some static inserts, for example
INSERT INTO TABLE_2011_08
WHERE Datafields = 2011_08
However i want it to be dynamic, so i was thinking something along the lines of a function/stored procedure to pass in the date for each record. However my brain is melting a bit with this!
The data records in the staging table could be something like this:-
RecordA 2011-08-30 Data Data Data
RecordB 2011-08-31 Data Data Data
RecordC 2011-09-01 Data Data Data
RecordD 2011-09-02 Data Data Data
The table T is similar to your table, I populated it with test data close to yours, the tables you populate will be created if they don’t exist.
An attempt to recreate your table
This syntax will if needed create and populate tables like TABLE_YYYY_MM. YYYY and MM is any combination found it table T