We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

SQL odd query

Medium Priority
345 Views
Last Modified: 2012-08-14
I'm inheriting some sql from a previous developer and I came across something that I haven't seen before and i was wondering if there is some logic here that I'm not aware of:

My concern is on the @yr variable that is being multiplied by 4. The value being passed in is a typical 4 digit year (2010, 2011 ect). Any ideas as to why this date would be multiplied?

SELECT DISTINCT yr, 
                          qtr, 
                          qratenat, 
                          obmediannat, 
                          measnum 
          FROM   dbo.globalresults 
          WHERE  numofmns = @NumOfMns 
                 AND ( yr * 4 + qtr ) IN (SELECT MAX(yr * 4 + qtr) 
                                          FROM   dbo.globalresults 
                                          WHERE  numofmns = @NumOfMns 
                                                 AND NOT ( qratenat IS NULL 
                                                           AND obmediannat IS 
                                                               NULL 
                                                         ) 
                                                 AND ( yr * 4 + qtr ) <= 
                                                     ( @Yr * 4 + @Qtr )) 

Open in new window

Comment
Watch Question

Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.