Solved

Colsolidate 2 views SQL

Posted on 2011-03-01
2
234 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
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL server 2008 and after encryption method 32 44
Addition to SQL for dynamic fields 6 37
T-SQL: "HAVING CASE" Clause 1 23
sql server service accounts 4 19
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how the fundamental information of how to create a table.

813 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now