Solved

Need help understanding a query

Posted on 2015-02-16
3
75 Views
Last Modified: 2015-02-16
I need help understanding this query. Is the query inserting records into the table CORE_ADMN_PSUS_PR_STE_USERS ???

Also, isn't there are bug at line 2.????, because this would basically delete the data that was selected into the temp table at line 2?



1.  SELECT * INTO #TEMP_PR FROM STAGING_BLLD_USER_DETAILS

2.  DELETE T FROM #TEMP_PR T
3.  INNER JOIN CORE_ADMN_PSUS_PR_STE_USERS S
4.  ON T.SECA_ASSOC_NUM = S.SECA_ASSOC_NUM
5.  AND T.PSUS_USER_ID = S.PSUS_USER_ID

6.  INSERT INTO (
7.  SECA_ASSOC_NUM,
8.  PSUS_USER_ID,CORE_ADMN_PSUS_PR_STE_USERS
9.  PSUS_EFF_DATE,
10. PSUS_END_DATE,
11. PSUS_ACTIVE
12.              )

13. SELECT
14. SECA_ASSOC_NUM,
15. PSUS_USER_ID,
16. PSUS_EFF_DATE,
17. PSUS_END_DATE,
18. PSUS_ACTIVE

19. FROM
20. #TEMP_PR

21. WHERE PSUS_USER_ID NOT IN (
22. SELECT FUUP_USUS_ID_OLD
23. FROM CORE_FCTS_FUUP_UPD_USUS_ID
                                  )
0
Comment
Question by:brgdotnet
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 480 total points
ID: 40613162
you are missing the destination table name on line 6

INSERT INTOCORE_ADMN_PSUS_PR_STE_USERS   (
  SECA_ASSOC_NUM,
0
 
LVL 48

Assisted Solution

by:PortletPaul
PortletPaul earned 20 total points
ID: 40613164
This has been subject to a previous question where I stated it needed more input from you. The SQL snippet above has syntax errors and isn't a working query, so trying to describe what it currently does isn't very fruitful.

It seems there is a missing table reference, and when that is fixed (see line 12) it looks like this:
SELECT
      *
INTO #TEMP_PR
FROM STAGING_BLLD_USER_DETAILS

DELETE T
      FROM #TEMP_PR T
      INNER JOIN CORE_ADMN_PSUS_PR_STE_USERS S
            ON T.SECA_ASSOC_NUM = S.SECA_ASSOC_NUM
            AND T.PSUS_USER_ID = S.PSUS_USER_ID

INSERT INTO some_table_missing_here
      SELECT
            SECA_ASSOC_NUM
          , PSUS_USER_ID
          , PSUS_EFF_DATE
          , PSUS_END_DATE
          , PSUS_ACTIVE

      FROM #TEMP_PR

      WHERE PSUS_USER_ID NOT IN (
                  SELECT
                        FUUP_USUS_ID_OLD
                  FROM CORE_FCTS_FUUP_UPD_USUS_ID
            )

Open in new window


What is the correct table on line 12? What were you expecting of this query?
0
 
LVL 2

Author Closing Comment

by:brgdotnet
ID: 40613345
Hi, thanks Experts. No Paul, the question is very different. I am looking at an entirely different block of code, here and the subject of the bug is the insert which is missing the table name. You have helped me before, and I am so very grateful sir. Seriously though, this was something slightly different.

Thanks Aneesh.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

708 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

16 Experts available now in Live!

Get 1:1 Help Now