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  | 
                             
                            
                                    | 
                                         zero1de 
                                        Posting Yak  Master 
                                         
                                        
                                        105 Posts  | 
                                        
                                        
                                            
                                            
                                             Posted - 2014-07-26 : 16:01:16
                                            
  | 
                                             
                                            
                                            | I need help to create the right SQL statment for my issue.In the table are two different values separated by counter. FIELDNR- the Cardnr (021)- the percent to Cardnr (022)- PSNR is Personalnr from each Employee- PFLFDNR is a seq. number for the fields 21 and 22 it show how many rows each Fieldnr already hasThe values are identified with the help of the date field PFGLTFROM and PFGLTTO. You must select of both records from a Personalnr always one active date out. Example: FIRMA	PSNR	FIELDNR	PFLFDNR	VALUE		PFGLTFROM		PFGLTTORows for Persnr=64 and Cardnr=21 in different times (but we need only one record which is valid from and to date1		64		021		1		2901009749	20110101		201405311 		64 		021 	2 		24			20140601 		20321231Rows for Persnr=64 and Cardnr=22 Percent in different times (but we need only one record which is valid from and to date1 		64 		022 	1 		1			20110101 		201207311 		64 		022 	2 		0			20120801 		201209071 		64 		022 	3 		0.77 		20120908 		20120930............................1 		64 		022 	9 		0			20140714 		201408151 		64 		022 	10 		1			20140816 		20320101Parameter: From and To DateThis should be the OutputThxzero1deI select the 2.row from Field=021 because it has the actual date PFGLTFROM=2014.06.01 PFGLTTO=2032.12.31and the value from Fieldnr=22 is 1 because it has the actual date PFGLTFROM=20140816 PFGLTTO=20320101FIRMA	PSNR	FELDNR	PFLFDNR	Value1	Value2		PFGLTFROM		PFGLTTO1			64		021		2		24		1			20140601		20321231I hope I could explain my problem :) | 
                                             
                                         
                                     | 
                             
       
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |