Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

Starting Member

1 Posts

Posted - 03/03/2014 :  06:04:51  Show Profile  Reply with Quote
Hi, could anyone please help with with following SQL reguest?

xy AS
(select a,b
from XXX
where time=201301),
xx AS
(select c,d,e,f,g
from YYY
where year=2013 and month=1)
select a,b,c,d,e,f,g
from xx
left join xy on xy.a=xx.b

The problem is that I have no idea, how to write one reguest that would generate results for the whole year. So basically I have to rewrite this request for each month (so time=201302 for month=2 etc.)

I am sure it is not difficult task, but I can not solve it.

Many thanks

Edited by - Ondra on 03/03/2014 06:28:19

Starting Member

11 Posts

Posted - 03/03/2014 :  08:55:46  Show Profile  Reply with Quote
Can you include some sample data? It's difficult to help without it...:) There are numerous ways to filter for a year at a time....where year = 2013....leave out the month. Of course I may be way off base....not knowing exactly what you're trying to achieve.
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 03/03/2014 :  11:43:34  Show Profile  Reply with Quote
As i understand you want make filter for full year


where year=2013

and the group by year,month to get result for each month

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000