March 14, 2013 at 2:24 pm
I have one current table and one history table. current table has three additional columns. Is it possible to join these two tables using union statement. I can not add columns to the history table. How to do it?
March 14, 2013 at 3:03 pm
seshagirikudaravalli (3/14/2013)
I have one current table and one history table. current table has three additional columns. Is it possible to join these two tables using union statement. I can not add columns to the history table. How to do it?
Both queries MUST have the same columns but that doesn't mean you can't make a derived column if needed.
something like this might work for you.
select col1, col2, col3, col4, col5 from CurrentTable
union all
select col1, col2, null, null, null from HistoryTable
In this code col3, col4 and col5 represent the columns in the current table not present in the history table.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy