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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Select rows grouped in 2 years (but not always)

Author  Topic 

Danzig
Starting Member

1 Post

Posted - 2010-08-19 : 20:27:20
Hi

I have a table of artwork records, each has a year assigned to it. The results will be displayed in a grid of descending 2 yearly bands. So the first row in the grid might be 2009 - 2010. The second row in the grid might be 2008 - 2009. And the third grid row might be 2006 - 2007.

But then the oldest artwork in the collection might be from 2005. So the last grid row would then only contain works from 2005.

Also, the years of the artworks may not be consecutive. eg. The first row of the grid might be 2009 - 2010, but then the second row might need to be 2005 - 2006, and the third and final row might be 2001 only.

Also... I only want them grouped in two yearly lots if those years are consecutive. eg. The first row of the grid might be 2009 - 2010 but if the next years in descending order are 2004 and 1999 then I want to display those in separate rows. ie. NOT 1999 - 2004

Is all this feasible with a single SELECT query? If so, please show me what it should look like!

Thanks in advance.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-08-19 : 21:49:06
please show us some sample data and expected result


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-20 : 12:33:50
you can do that. How is year value stored in your system? so any time how many years data you will show?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -