Solved

What is this SQL Code doing?

Posted on 2012-03-30
6
234 Views
Last Modified: 2012-03-30
Can someone tell me what "umc" is referencing, or how it is being populated in this query.  
I have a basic understanding of the #temp for temp tables but I am a bit puzzled with what is going on with "umc".
umc.txt
0
Comment
Question by:morinia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 9

Accepted Solution

by:
OCDan earned 400 total points
ID: 37788446
Basically they have just called the larger query below UMC. It is just an alias for the query it is the equivalent of OH in the below query:
select * from orderheader as OH

Your query:
(
--QUERY1
SELECT
  mc.member_id, mc.enrollment_date , mc.exit_date
, mc.primary_secondary , mc.active_code , mc.benefit_plan
, mc.benefit_product, mc.benefit_group, 'CURR' as ONFILE
from llm.llmdba.member_coverage mc (nolock)
   , #mbrLkup m (nolock)
where
   mc.enrollment_date < '01/01/2012'
  and (mc.exit_date >= '01/01/2011' or mc.exit_date is null)
  and (convert(varchar(10),mc.enrollment_date,120) <> convert(varchar(10),mc.exit_date,120) or mc.exit_date is null)
  and mc.member_id = m.member_id
union
--QUERY2
SELECT
  mc.member_id, mc.enrollment_date, mc.exit_date, mc.primary_secondary
, mc.active_code, mc.benefit_plan, mc.benefit_product, mc.benefit_group, 'HIST' as ONFILE
from llm.llmdba.member_coverage_history mc (nolock), #mbrLkup m (nolock)
where
      mc.enrollment_date < '01/01/2012'  and (mc.exit_date > '01/01/2011' or mc.exit_date is null)
  and (convert(varchar(10),mc.enrollment_date,120) <> convert(varchar(10),mc.exit_date,120) or mc.exit_date is null)
  and mc.member_id = m.member_id
) umc

Hope that helps.
0
 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 100 total points
ID: 37788464
umc is referencing the results of the sub-select that starts on line 40 and finishes on line 86:

into #mbr_covg0
from
(     <------    starts here
SELECT
  mc.member_id
...
...
) umc    <-- finishes here
0
 

Author Comment

by:morinia
ID: 37788508
SELECT umc.*
, dense_rank()
       over (partition by umc.member_id
             order by umc.enrollment_date desc
                    , umc.exit_date)
       as nRank

What is the first six lines of the code doing?
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 9

Assisted Solution

by:OCDan
OCDan earned 400 total points
ID: 37788520
select umc.*
selects all the fields from UMC subquery as said above

Dense_rank():
Ranks the results per each umc.member_id with the most recent enrollment date and the earliest exit date being the highest ranked.

Have a read of this link on
Ranking Functions it should help you understand the dense_rank function a bit better.
0
 

Author Comment

by:morinia
ID: 37788594
The use of temporary tables and partitions is this regular SQL or Transact-Sql?  Since you are able to access temproary tables as well as the tables on the server what differentiates this code from regular  MSSql code?
0
 
LVL 9

Expert Comment

by:OCDan
ID: 37788603
Yes they get used quite a lot in TSQL soryr mate not sure what you mean by regular SQL.

This is valid MSSQL(TSQL) code, copying it into Sql Server Management Studio and performing a syntax check runs fine, so it is likely valid.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
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.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

688 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