SELECT CASE WHEN CAST(date1 AS DATE) <= CAST(date2 AS DATE) ...
Should do what you need.
Test Case
WITH dates(date1, date2, date3, date4) AS (SELECT CAST('20101231 15:13:48.593' AS DATETIME), CAST('20101231 00:00:00.000' AS DATETIME), CAST('20101231 15:13:48.593' AS DATETIME), CAST('20101231 00:00:00.000' AS DATETIME)) SELECT CASE WHEN CAST(date1 AS DATE) <= CAST(date2 AS DATE) THEN 'Y' ELSE 'N' END AS COMPARISON_WITH_CAST, CASE WHEN date3 <= date4 THEN 'Y' ELSE 'N' END AS COMPARISON_WITHOUT_CAST FROM dates
Returns
COMPARISON_WITH_CAST | COMPARISON_WITHOUT_CAST Y N
Related Posts:
- MS SQL compare dates?
- T-SQL split string
- How can I get column names from a table in SQL Server?
- Using RegEx in SQL Server
- Comma separated results in SQL
- Inserting multiple rows in a single SQL query? [duplicate]
- SQL Query with NOT LIKE IN
- T-SQL split string based on delimiter
- How do I perform an IF…THEN in an SQL SELECT?
- An attempt was made to access a socket in a way forbidden by its access permissions
- Conversion of a varchar data type to a datetime data type resulted in an out-of-range value in SQL query
- Each GROUP BY expression must contain at least one column that is not an outer reference
- SQL Server : Arithmetic overflow error converting expression to data type int
- How to calculate percentage with a SQL statement
- Query comparing dates in SQL
- What is the meaning of the prefix N in T-SQL statements and when should I use it?
- Query error with ambiguous column name in SQL
- Keeping it simple and how to do multiple CTE in a query
- How can I delete using INNER JOIN with SQL Server?
- Why use a READ UNCOMMITTED isolation level?
- Conversion of a varchar data type to a datetime data type resulted in an out-of-range value in SQL query
- How to group by month from Date field using sql
- SQL – The conversion of a varchar data type to a datetime data type resulted in an out-of-range value
- Is there a combination of “LIKE” and “IN” in SQL?
- How to get a date in YYYY-MM-DD format from a TSQL datetime field?
- How do I fix ‘Invalid character value for cast specification’ on a date column in flat file?
- What is the maximum characters for the NVARCHAR(MAX)?
- Get size of all tables in database
- How to format a numeric column as phone number in SQL
- sql query to return differences between two tables
- How do I format a number with commas in T-SQL?
- SQL: IF clause within WHERE clause
- To add server using sp_addlinkedserver
- How can I group by date time column without taking time into consideration
- How to select the last record of a table in SQL?
- SHOWPLAN permission denied in database ‘tempdb’. in sql server 2008
- Varchar invalid for Sum operator
- Selecting COUNT(*) with DISTINCT
- What is a stored procedure?
- LEFT JOIN vs. LEFT OUTER JOIN in SQL Server
- LEFT JOIN vs. LEFT OUTER JOIN in SQL Server
- How to drop a table if it exists?
- SQL Server: Difference between PARTITION BY and GROUP BY
- Self Join to get employee manager name
- When should I use CROSS APPLY over INNER JOIN?
- Rename column SQL Server 2008
- Efficiently convert rows to columns in sql server
- How to delete duplicate rows in SQL Server?
- The SQL OVER() clause – when and why is it useful?
- Update multiple columns in SQL
- Function to Calculate Median in SQL Server
- SQL Server IF EXISTS THEN 1 ELSE 2
- SQL Server Management Studio, how to get execution time down to milliseconds
- How do I escape a single quote in SQL Server?
- Column name or number of supplied values does not match table definition
- SQL Server FOR EACH Loop
- The EXECUTE permission was denied on the object ‘xxxxxxx’, database ‘zzzzzzz’, schema ‘dbo’
- How to drop all tables from a database with one SQL query?
- Sql Server string to date conversion
- Invalid length parameter passed to the LEFT or SUBSTRING function
- Conversion failed when converting from a character string to uniqueidentifier – Two GUIDs
- Operand type clash: int is incompatible with date + The INSERT statement conflicted with the FOREIGN KEY constraint
- Find all tables containing column with specified name – MS SQL Server
- DateTime2 vs DateTime in SQL Server
- SQL Server Insert if not exists
- CREATE TABLE IF NOT EXISTS equivalent in SQL Server
- How can I import an Excel file into SQL Server?
- SQL Server: Invalid Column Name
- sql server invalid object name – but tables are listed in SSMS tables list
- SQL Connection Error: System.Data.SqlClient.SqlException (0x80131904)
- Search text in stored procedure in SQL Server
- Arithmetic overflow error converting expression to data type datetime. (while displaying date time..)
- Error converting data type varchar to float
- I want to use CASE statement to update some records in sql server 2005
- What represents a double in sql server?
- SELECT DISTINCT on one column
- TSQL PIVOT MULTIPLE COLUMNS
- Microsoft OLE DB Provider for SQL Server error ‘80004005’
- Difference between database and schema
- Why do table names in SQL Server start with “dbo”?
- SQL Server Linked Server Example Query
- Equivalent of Oracle’s RowID in SQL Server
- How do I fix the error ‘Named Pipes Provider, error 40 – Could not open a connection to’ SQL Server’?
- Is it possible to specify condition in Count()?
- SQL datetime compare
- SQL Server dynamic PIVOT query?
- Backup a single table with its data from a database in sql server 2008
- How to write a foreach in SQL Server?
- Error converting data type varchar
- Temporary table in SQL server causing ‘ There is already an object named’ error
- I want to use CASE statement to update some records in sql server 2005
- ORDER BY items must appear in the select list if SELECT DISTINCT is specified
- Text was truncated or one or more characters had no match in the target code page including the primary key in an unpivot
- SQL- Ignore case while searching for a string
- SQL WHERE.. IN clause multiple columns
- SUM OVER PARTITION BY
- Filter data based on date in sql
- How to truncate string using SQL server
- What is tableName.* in SQL
- How to connect to database from Unity