| 
                
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. 
    
        | 
                
                    | 
                            
                                | Author | Topic |  
                                    | xholaxStarting Member
 
 
                                        12 Posts | 
                                            
                                            |  Posted - 2013-03-18 : 19:16:32 
 |  
                                            | Hello friends hope you can help me, i need the below query for my job but i cant get it :( :  --Sample DataDECLARE @Foo TABLE (oper CHAR(10), [start] int, [end] int , [status] int )INSERT @Fooselect 'James', 0,3,2 union allselect 'James', 3,5,2 union allselect 'James', 5,8,3 union allselect 'James', 8,9,4 union allselect 'James', 9,10,2 union allselect 'James', 10,14,2 union allselect 'James', 14,48,3select * from @Foothanks in advance |  |  
                                    | James KMaster Smack Fu Yak Hacker
 
 
                                    3873 Posts | 
                                        
                                          |  Posted - 2013-03-18 : 19:41:22 
 |  
                                          | [code];with cte as(	select *, 		ROW_NUMBER() over (order by start,[end])-		ROW_NUMBER() over (PARTITION by status order by start,[end]) Grp	from		@Foo)select	oper,	MIN(start) [start],	MAX([end]) [end],	statusfrom	ctegroup by	oper,	status,	grporder by 	[start],	[end][/code] |  
                                          |  |  |  
                                    | xholaxStarting Member
 
 
                                    12 Posts | 
                                        
                                          |  Posted - 2013-03-18 : 23:05:13 
 |  
                                          | thanks it works perfect, i didnt know about that kind of query partitions and rank where i can find more info about that , some recommend book ? |  
                                          |  |  |  
                                |  |  |  |  |  |