Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

SQL odd query

Posted on 2011-04-25
1
Medium Priority
?
319 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

0
Comment
Question by:jgoodale
1 Comment
 
LVL 41

Accepted Solution

by:
ralmada earned 2000 total points
ID: 35461427
to get the total number of quarters. So 2010 will have 8040 quarters.
0

Featured Post

Technology Partners: 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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

580 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