Topic: Help with a simple problem !

All greetings.
I ask the help in the decision, apparently, the simple task.
There are two tables:
Sales (sale Date, the Total)
Course (course Date, Course)
It is necessary them  so that to each date of sale there would correspond the course.
Problem in that the Course is not always installed in sale date (can head which has been installed yesterday or the day before yesterday).
My request works not correctly.
Help .

cast ([Sale]. [Sale Date] as date) as ' sale Date ';
[Sale]. [Total];
[Course]. [Course]
from [Sale]
left join [Course] on cast ([Sale]. [Sale Date] as date) = (SELECT max (cast ([Course]. [Course Date] as date)) as MaxDate
FROM [Course]
WHERE cast ([Sale]. [Sale Date] as date)> = cast ([Course]. [Course Date] as date)


Re: Help with a simple problem !

DB: Microsoft SQL Server 2016 (SP1) - 13.0.4001.0


Re: Help with a simple problem !

select *
from Sales 
outer apply (
select top 1 *
from Course to
k.date <= the item date
order by
k.date desc
) k

What to do with sales without course, understand


Re: Help with a simple problem !

Shyfl and msLex Big to you human thanks! smile