Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / General / Data Warehousing / December 2004

Tip: Looking for answers? Try searching our database.

SQL Table name in a query, HELP!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Co-op Bank - 07 Dec 2004 14:05 GMT
Hello, im trying to extract and merge data from several tables into one
table, to indetify which table each row of data has come from I would like to
insert a column which references the table name. Below is an example of the
code:-
I would like to create a column which will show for example
'summed_corp_tin_t_20041115' next to its respective data. Please help!

SELECT   summed_corp_tin_t_20041115.record_type,
        summed_corp_tin_t_20041115.payment_type,
        (SUM (summed_corp_tin_t_20041115.COUNT)) sum_count,
        (SUM (summed_corp_tin_t_20041115.tran_amount)) sum_amount
   FROM summed_corp_tin_t_20041115
GROUP BY summed_corp_tin_t_20041115.record_type,
        summed_corp_tin_t_20041115.payment_type
UNION
SELECT   summed_corp_tin_t_20041018.record_type,
        summed_corp_tin_t_20041018.payment_type,
        (SUM (summed_corp_tin_t_20041018.COUNT)) sum_count,
        (SUM (summed_corp_tin_t_20041018.tran_amount)) sum_amount
   FROM summed_corp_tin_t_20041018
GROUP BY summed_corp_tin_t_20041018.record_type,
        summed_corp_tin_t_20041018.payment_type

Any help much appreciated.

Thanks

Brian
Manchester, England
Jacco Schalkwijk - 07 Dec 2004 14:27 GMT
Your question has been answered in the .programming newsgroup.Please don't
multipost.

Signature

Jacco Schalkwijk
SQL Server MVP

> Hello, im trying to extract and merge data from several tables into one
> table, to indetify which table each row of data has come from I would like
[quoted text clipped - 27 lines]
> Brian
> Manchester, England
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.