×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Making a temp table out of a union

Making a temp table out of a union

Making a temp table out of a union

(OP)
I'm attempting to make a select union statement into it's own temp table. Essentially, the end of my query has

SELECT * FROM PAY_BILL
UNION
SELECT * FROM BILL_ADJ_WE

And I want to create a more consolidated select statement, because I don't need all of the fields these two selects are retrieving. I also want to add a section that provides values from one table that correlate with values from another table. Any suggestions as to where I should begin? This is what I've attempted but it didn't work. It should also be noted, the actual query works, but when I attempt to add this last temp table, the query blows up.

                                         ,

PRELIM_DATA (INVOICE, CUST_ID, CUSTOMER_NAME, ASSIGNMENT_OWNING_DEPTID, ORDER_OWNING_DEPTID,
VENDOR_ID, VENDOR_NAME, BUSINESS_UNIT, PROJECT_ID, ACTIVITY_ID, EMPLID, EMPL_RCD, NAME,
FOBU, ORDER_ID, ASSIGNMENT_ID,JOBTITLE, CLIENT_JOB_TITLE,
PROJECT_DESCR, PROJECT_TYPE, LINE_OF_BUSINESS, SERVICE_LINE,
ACCOUNTING_DT, WE_DATE, ANALYSIS_TYPE, RESOURCE_CATEGORY,
TIME_RPTG_CD, HOURS, AMOUNT)

AS
(
SELECT * FROM PAY_BILL
UNION
SELECT * FROM BILL_ADJ_WE
)
,

This will provide me with Resource category values
RES_CAT(RESOURCE_CATEGORY, TRC)
 AS
 (
 SELECT DISTINCT COALESCE (LN.TGT_RES_CATEGORY, ' ') AS RESOURCE_CATEGORY, TR.TRC
 FROM PS_TL_TRC_TBL TR LEFT OUTER JOIN PS_FO_RATE_PROFILE RP
 ON TR.TRC = RP.TIME_RPTG_CD
 LEFT OUTER JOIN PS_FO_RATE_PRFL_LN LN
 ON LN.SETID = RP.SETID
 AND LN.RATE_PROFILE_TYPE = RP.RATE_PROFILE_TYPE
 AND LN.DETAIL_NO = RP.DETAIL_NO
 AND LN.SEQ_NUM = RP.SEQ_NUM
 )

Final Select statement
SELECT A.INVOICE,
       A.CUST_ID,
       A.CUSTOMER_NAME,
--        A.ASSIGNMENT_OWNING_DEPTID,
       A.ORDER_OWNING_DEPTID,
       A.VENDOR_ID,
       A.VENDOR_NAME,
--        A.BUSINESS_UNIT,
--        A.PROJECT_ID,
--        A.ACTIVITY_ID,
       A.EMPLID,
       A.EMPL_RCD,
       A.NAME,
--        A.FOBU,
--        A.ORDER_ID,
--        A.ASSIGNMENT_ID,
--        A.JOBTITLE,
       A.CLIENT_JOB_TITLE,
       A.PROJECT_DESCR,
--        A.PROJECT_TYPE,
       A.LINE_OF_BUSINESS,
       A.SERVICE_LINE,
       A.ACCOUNTING_DT,
       B.END_DT AS WE_DATE,
       A.ANALYSIS_TYPE,
       A.RESOURCE_CATEGORY,
       A.TIME_RPTG_CD,
       SUM(B.QTY) AS HOURS,
       SUM(B.NET_EXTENDED_AMT) AS AMOUNT

FROM PRELIM_DATA A INNER JOIN RES_CAT B
        ON A.RESOURCE_CATEGORY = B.RESOURCE_CATEGORY




GROUP BY A.INVOICE,
       A.CUST_ID,
       A.CUSTOMER_NAME,
--        A.ASSIGNMENT_OWNING_DEPTID,
       A.ORDER_OWNING_DEPTID,
       A.VENDOR_ID,
       A.VENDOR_NAME,
--        A.BUSINESS_UNIT,
--        A.PROJECT_ID,
--        A.ACTIVITY_ID,
       A.EMPLID,
       A.EMPL_RCD,
       A.NAME,
--        A.FOBU,
--        A.ORDER_ID,
--        A.ASSIGNMENT_ID,
--        A.JOBTITLE,
       A.CLIENT_JOB_TITLE,
       A.PROJECT_DESCR,
--        A.PROJECT_TYPE,
       A.LINE_OF_BUSINESS,
       A.SERVICE_LINE,
       A.ACCOUNTING_DT,
       B.END_DT AS WE_DATE,
       A.ANALYSIS_TYPE,
       A.RESOURCE_CATEGORY,
       A.TIME_RPTG_CD

As you can see, I am attempting to take the information from the initial query and connect it to a new temp table that that will provide me with values that will populate sections that were originally left blank. Any help is much appreciated. I don't know if I have explained myself correctly, so I will be monitoring in case anyone needs any more information. Thank you very much.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close