Over the next few days we are going to start the migration to a new forum application. I'm going to start with high post count and active users. You may receive an invitation to the new forums. It's not spam. It's just me trying to seed the user base. My goal is to open it up over the weekend.

Once we open the site we'll block registrations here. We should be open shortly on the new site.

SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 combined conditions
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

249 Posts

Posted - 02/20/2014 :  13:55:51  Show Profile  Reply with Quote
Hi there,

I have a table with column of Year and Quarter like this:

Year | Qt | Score ...
2013 | 3 | 213
2013 | 4 | 143
2014 | 1 | 342
2014 | 2 ...

Now I need select some rows between Quarter 4 in previous year and current Quarter and only 4 Quarters allowed totally. How can I do that?
Thanks in advance.

Flowing Fount of Yak Knowledge

6065 Posts

Posted - 02/20/2014 :  14:01:00  Show Profile  Reply with Quote
one way:

where ([year]*10)+[qt] between 20134 and 20144

Be One with the Optimizer
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 02/20/2014 :  14:01:49  Show Profile  Reply with Quote
        Year ,
        Qt ,
FROM    YourTable
WHERE	Year <= '2013' AND Qt <= 3 -- if you want a starting point
Go to Top of Page

Posting Yak Master

249 Posts

Posted - 02/20/2014 :  15:52:14  Show Profile  Reply with Quote
Thanks gents for reply. TG's idea is brilliant now I put both together as following:

Select top 4 YR, QT, Score
From myTable
where (YR * 10 + QT) between ((YEAR(GetDate()) - 1 ) * 10 + QT) and (YEAR(GetDate()) ) * 10 + QT
Order by YR desc, QT desc

it works perfect!
thank you again.

Edited by - allan8964 on 02/20/2014 15:53:32
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000