Solved

Colsolidate 2 views SQL

Posted on 2011-03-01
2
237 Views
Last Modified: 2012-06-22
Dear Experts

I have two views with exactly the same amount of columns and column names.

Each of the views hold different data and I would like to create another view to consolidate the data.  Is this possible.

For Example

Table A                      Table B
pRef                           pRef
pAddress1                pAddress1
pAddress2                pAddress2
pTown                       pTown


Am I able to consolidate this data into (Table C)

Thanks


0
Comment
Question by:grantballantyne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
reb73 earned 250 total points
ID: 35007014
SELECT * INTO dbo.TableC
FROM
(SELECT * FROM dbo.TableA
 UNION ALL
 SELECT * FROM dbo.TableB
) as Tmp
0
 
LVL 8

Assisted Solution

by:Forefront_Data_Solutions
Forefront_Data_Solutions earned 250 total points
ID: 35007021
The simplest way would be to use the UNION operator.  Copy the SQL from View A add the UNION operator, then copy the SQL from View B.  Like this:

Select somestuff
from ATable

UNION

Select someotherstuff
from BTable


The most efficient way would be to analyze the data from the original two tables and write a query that retrieves the desired data.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question