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 |  
                                    | annPosting Yak  Master
 
 
                                        220 Posts | 
                                            
                                            |  Posted - 2013-08-23 : 16:46:46 
 |  
                                            | I need to find the row of Itemx and Discount from table b based on the SoldDate from table A. TableB SalesStartDate the items are on discount until the next SalesStartDate.  For Example, I need to know the item and discount that was in effect when the solddate was 09/10/2011 - the SalesStartDate the discount is good until the next SalesStartDate and then the new Discount is applied:Table A:ColumnA     ColumnB    SoldDateblah        blah       09/10/2011Table B:Itemx          Discount       SalesStartDatet-shirt        10%            11/01/2011leggings       10%            09/03/2011fleece pants   15%            09/01/2011Results wanted:leggings    10%Don't know how clear I'm being, but any help would be appreciated.Thanks |  |  
                                    | annPosting Yak  Master
 
 
                                    220 Posts | 
                                        
                                          |  Posted - 2013-08-23 : 17:04:34 
 |  
                                          | Re-reading this, maybe I'm not being very clear - I need to find the closest or equal date in TableB based on the SoldDate of TableA, but the date in TableB cannot be greater than the SoldDate in table A |  
                                          |  |  |  
                                    | annPosting Yak  Master
 
 
                                    220 Posts | 
                                        
                                          |  Posted - 2013-08-23 : 17:44:37 
 |  
                                          | Figured this out:SELECT *FROM TableBWHERE SalesStartDate= (SELECT MAX(SalesStartDate)FROM TableBWHERE SalesStartDate <= '09/10/2011') |  
                                          |  |  |  
                                |  |  |  |