|
-
Nov 17th, 2003, 09:46 AM
#1
Help merging 2 tables
I have 2 tables Site_2002 and Site_2003. These represent the same data from different years. Instead of continuing to create new tables each year, I would like to merge these tables into a single table.
What I’m looking to do is create a new table with a Fiscal Year column. Add the contents of Site_2002 and Site_2003 to the new table and at the same time set the values of the FY column to match whichever table the data is coming from.
Could someone give me an idea on how to start this? I’m not very good with SQL and I’m not sure which functions are needed to pull this off. I hope with a nudge in the right direction I can figure this out. Any pseudo code would be greatly appreciated.
-
Nov 17th, 2003, 03:08 PM
#2
If your using Access:
Add your new Fiscal_Year field to the first table and use it as the
base. Populate the new field with 2002. Then rename Site_2002
to something like Site_Data. Then select the Site_2003 table and
copy it and paste it to the Site_Data table name and select
Append data to existing table option. Then populate the
remaining empty Fiscal_Year fields with 2003.
If your using SQL server then:
Use the INSERT INTO statement.
Create the new filed Fiscal_Year in 2002. Populate it with 2002.
Then create a default on that field of "YEAR(GetDate())".
Then execute a statement like ...
INSERT INTO
Site_2003 (Col1, Col2, Col3...)
VALUES
(SELECT * FROM Site_2003)
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 17th, 2003, 07:03 PM
#3
Thanks for the suggestion. This is a SQl db. What I was looking into was adding a Fiscal_Year to both of the tables and updating it with the correct year. Then I was going to try to use a Union between the 2 table to create the final table. Does that seem like it may work?
-
Nov 17th, 2003, 07:08 PM
#4
Yes, that sound ok. Are you going to keep every year in
separate tables? A union may end up being too resource
intensive once you need to query the union for reports, etc.
May be better to have the one table with all records in it then
just have to execute one query on the table. Not union the two
tables and then execute the query on it. Just something to keep in mind.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|