?
Solved

Need help understanding a query

Posted on 2015-02-16
3
Medium Priority
?
99 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 1920 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 49

Assisted Solution

by:PortletPaul
PortletPaul earned 80 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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Suggested Courses

850 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