Solved

Need help understanding a query

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL query and VBA 5 46
Run Stored Procedure uisng ADO 5 24
Isolation level setting TSQL View 10 30
interpreting data from function COLUMNS_UPDATED 2 18
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

808 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