SQL odd query

Posted on 2011-04-25
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?

          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 
                                                 AND ( yr * 4 + qtr ) <= 
                                                     ( @Yr * 4 + @Qtr )) 

Open in new window

Question by:jgoodale
    1 Comment
    LVL 41

    Accepted Solution

    to get the total number of quarters. So 2010 will have 8040 quarters.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now