Solved

Need help understanding a query

Posted on 2015-02-16
3
82 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

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…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

773 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