| 
                
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 |  
                                    | zaroblanStarting Member
 
 
                                        6 Posts | 
                                            
                                            |  Posted - 2010-10-19 : 08:35:42 
 |  
                                            | Greetings,I have a table with three columns:RowID int identity (1,1)TimeSent datetimeEventType intFor arguments sake say the two events I am interested in are events number 4 (start) and 5 (stop)I need to select all rows where 1) the last of either a start or stop BEFORE required date is a start 2) the first start (4) AFTER required date is a start if the last start/stop in 1) above was a stop (5)I believe this sort of thing is possible in MySQL using the FIRST construct which is not available in SQL 2000.Thanks,Robert |  |  
                                    | webfredMaster Smack Fu Yak Hacker
 
 
                                    8781 Posts | 
                                        
                                          |  Posted - 2010-10-19 : 08:38:02 
 |  
                                          | Maybe you can help us to help you?  No, you're never too old to Yak'n'Roll if you're too young to die.
 |  
                                          |  |  |  
                                    | zaroblanStarting Member
 
 
                                    6 Posts | 
                                        
                                          |  Posted - 2010-10-19 : 08:53:57 
 |  
                                          | While I am a big fan of both Judas Priest and AC DC the response given does not help me at all.Please could you be more specific.Thanks. |  
                                          |  |  |  
                                    | pk_bohraMaster Smack Fu Yak Hacker
 
 
                                    1182 Posts | 
                                        
                                          |  Posted - 2010-10-19 : 08:57:31 
 |  
                                          | Hi zaroblan,Webfred means that your requirement is not completly clear to us to help you. Please provide some sample data and your expected output. This will help us in understanding your requirement and we will be able to help you.Regards,Bohra |  
                                          |  |  |  
                                    | webfredMaster Smack Fu Yak Hacker
 
 
                                    8781 Posts | 
                                        
                                          |  Posted - 2010-10-19 : 09:11:41 
 |  
                                          | quote:WOW! That's greatWhile I am a big fan of both Judas Priest and AC DC ...
 
  Next time I will try to be more clear when I am asking other people to be more clear  No, you're never too old to Yak'n'Roll if you're too young to die.
 |  
                                          |  |  |  
                                    | webfredMaster Smack Fu Yak Hacker
 
 
                                    8781 Posts | 
                                        
                                          |  Posted - 2010-10-19 : 09:12:53 
 |  
                                          | quote:Thank you for clarificationOriginally posted by pk_bohra
 Hi zaroblan,Webfred means that your requirement is not completly clear to us to help you. Please provide some sample data and your expected output. This will help us in understanding your requirement and we will be able to help you.Regards,Bohra
 
  No, you're never too old to Yak'n'Roll if you're too young to die.
 |  
                                          |  |  |  
                                    | zaroblanStarting Member
 
 
                                    6 Posts | 
                                        
                                          |  Posted - 2010-10-19 : 09:44:10 
 |  
                                          | Additonal clarification to original message: TableFieldUniqueId    int identity (1,1)TimeSent    datetimePersonId    intEventType   int     -- for this example use 4 for a start and 5 for a stop, always go from a start to a stopData01,19/10/2008 10:01:00,1,102,19/10/2008 10:02:00,2,4 03,19/10/2008 10:03:00,3,104,19/10/2008 10:04:00,4,405,19/10/2008 10:05:00,1,506,19/10/2008 10:06:00,1,1  <--- REQUIRED DATE RANGE START07,19/10/2008 10:07:00,2,508,19/10/2008 10:08:00,2,409,19/10/2008 10:09:00,1,410,19/10/2008 10:10:00,2,111,19/10/2008 10:11:00,3,412,19/10/2008 10:12:00,4,113,19/10/2008 10:13:00,1,1  <--- REQUIRED DATE RANGE END14,19/10/2008 10:14:00,4,515,19/10/2008 10:15:00,4,116,19/10/2008 10:16:00,1,1If my required datetime is 19/10/2010 10:06:00 what I expect to be returned is:02,19/10/2010 10:02:00,2,4  started before range we want this one04,19/10/2010 10:04:00,4,4  same as line above09,19/10/2010 10:09:00,1,4  person 's last (4 or 5 before the range was a 5, so this is the time we want00,19/10/2010 10:11:00,3,4  person 3 had no start or stop before the range, so we want the first start in the rangeIf latest start or stop (event 4 or event 5) BEFORE the range is a 4 we want this valueIf latest start or stop (event 4 or event 5) BEFORE the range is a 5 we want the the first 4 WITHIN the rangeThanks,Robert      |  
                                          |  |  |  
                                    | yonaboutPosting Yak  Master
 
 
                                    112 Posts | 
                                        
                                          |  Posted - 2010-10-21 : 10:26:11 
 |  
                                          | Hi,Could you tell us what the data represents in 'real life' and what you want to get from it? Is it something like a time recording system where you need to see how long users have spent doing stuff within a period?I'm probably being stoopid  , but to me, quote:just means the last start before the required date?And1) the last of either a start or stop BEFORE required date is a start
 
 quote:won't select anything because logically the result from step 1 will always be a start?Also, sometimes you mention a single specific date, and other times date ranges. Which do you want to account for? and are you wanting to include or exclude results around the date range?So if you could describe how you're trying to use the data in the real world it might make it a bit easier to get my head around.Cheers,Yonabout2) the first start (4) AFTER required date is a start if the last start/stop in 1) above was a stop (5)
 
 |  
                                          |  |  |  
                                |  |  |  |  |  |