Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Using Derived and Temp Tables

$
0
0

I'm selecting the same data from 2 different tables and dumping the results in one temp table.  In the temp table, how can I differientiate the data between the tables?  For instance, how can I count all records from each set of data and tell know the counts for each table?  For an example:

SELECT

INTO

#Temp1

FROM

(SELECT

COUNT(phonenumber)AS VBPSR1 FROM TableA

WHERE

length> 2


AND

callingmode <> 0--Non Dialer Call


and

iscontact=1


AND

reason='NotAvailable'


AND

finishcode ='NotAvailable'


AND

calltime >='1/1/13'


AND

calltime <'9/19/13'


GROUP



UNION

SELECT

COUNT(phonenumber)AS VBPSR2 FROMTableB

WHERE

length> 2


AND

callingmode <> 0--Non Dialer Call


and

iscontact=1


AND

reason='NotAvailable'


AND

finishcode ='NotAvailable'


AND

calltime >='1/1/13'


AND

calltime <'9/19/13'


GROUP

BY name,RIGHT(CONVERT(VARCHAR(10), calltime, 103), 7)) AS FIRSTCOUNT





Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>