The where clause will match all rows with date less than @CurrentDate and, since they are ordered descendantly, the TOP 1 will be the closest date to the current date.
SELECT TOP 1 *
FROM x
WHERE x.date < @CurrentDate
ORDER BY x.date DESC
More Related Contents:
- How to return only the Date from a SQL Server DateTime datatype
- Best approach to remove time part of datetime in SQL Server
- Get the week start date and week end date from week number
- How to determine the number of days in a month in SQL Server?
- Difference between datetime and timestamp in sqlserver? [duplicate]
- Query comparing dates in SQL
- SQL SERVER: Get total days between two dates
- SQL “between” not inclusive
- Date serial in SQL?
- Convert text to system date format [duplicate]
- How to get a particular preceding value of a column in SQL [closed]
- How to select just the row in the second table?
- SQL update from one Table to another based on a ID match
- What is the meaning of the prefix N in T-SQL statements and when should I use it?
- SQL JOIN vs IN performance?
- Generate SQL Create Scripts for existing tables with Query
- SQL Server 2005 How Create a Unique Constraint?
- Check if a row exists, otherwise insert
- Export SQL query data to Excel
- Alter user defined type in SQL Server
- Deferrable Constraints in SQL Server
- What does sp_reset_connection do?
- SQL Server equivalent to MySQL enum data type?
- How to correctly insert newline in nvarchar [duplicate]
- How to create Temp table with SELECT * INTO tempTable FROM CTE Query
- SELECT max(x) is returning null; how can I make it return 0?
- How to return default value from SQL query
- Group consecutive rows of same value using time spans
- Conditional aggregation performance
- SQL add filter only if a variable is not null