0

I have a set of data logs from a machine that I would like to combine into a single table. However older data logs have different columns than newer ones (certain variables were added/tracked later on).

I mocked up an example in Excel that I am trying to mimic in my Microsoft SQL database. I can't determine the query to use.

Thank you for any help!

EDITS: 1. I don't think this is a duplicate. 2. How many data logs? ~100 data log tables. 3. I am using MS SQL 4. I would prefer not to have to type out all the column names if possible, there are many.

Excel Diagram Example

Hi_Im_E
  • 1
  • 1

1 Answers1

0

You could use UNION

The query would look like this:

SELECT 
   date, 
   tim, 
   val1, 
   val2, 
   val3 
from dataset1 
union all
SELECT 
   date, 
   tim, 
   val1, 
   '' as val2, 
   val3 
 From dataset2

This will get the data from the 2 tables and null values in the dataset2 table where the column not exist.

MagdielAybar
  • 187
  • 1
  • 2
  • 12