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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL request

Author  Topic 

Ondra
Starting Member

1 Post

Posted - 2014-03-03 : 06:04:51
Hi, could anyone please help with with following SQL reguest?

With
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







kennejd
Starting Member

11 Posts

Posted - 2014-03-03 : 08:55:46
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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-03-03 : 11:43:34
As i understand you want make filter for full year

ie

where year=2013

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

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -