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
- What do Clustered and Non-Clustered index actually mean?
- Self Join to get employee manager name
- How do I UPDATE from a SELECT in SQL Server?
- SQL query to select dates between two dates
- SQL query to get the employee name and their manager name from the same table
- How can I do an UPDATE statement with JOIN in SQL Server?
- Function to Calculate Median in SQL Server
- Efficiently convert rows to columns in sql server
- How do I escape a single quote in SQL Server?
- What is the use of GO in SQL Server Management Studio & Transact SQL?
- SQL Query with SUM with Group By
- IDENTITY_INSERT is set to OFF – How to turn it ON?
- SQL update from one Table to another based on a ID match
- How to drop all tables from a database with one SQL query?
- Optimistic vs. Pessimistic locking
- The target principal name is incorrect. Cannot generate SSPI context
- BCP error “Unable to open BCP host data-file”
- How can I clone an SQL Server database on the same server in SQL Server 2008 Express?
- Delete all the records
- Each GROUP BY expression must contain at least one column that is not an outer reference
- SQL Server : error converting data type varchar to numeric
- How to find sum of multiple columns in a table in SQL Server 2005?
- Check if table exists in SQL Server
- How can I truncate a datetime in SQL Server?
- DateTime2 vs DateTime in SQL Server
- CREATE TABLE IF NOT EXISTS equivalent in SQL Server
- SQL Connection Error: System.Data.SqlClient.SqlException (0x80131904)
- SQL Server String or binary data would be truncated
- How to parse XML data in SQL server table
- How to convert SQL Server’s timestamp column to datetime format
- What is the equivalent of ‘describe table’ in SQL Server?
- What is the Oracle equivalent of SQL Server’s IsNull() function?
- ClassNotFoundException – com.microsoft.jdbc.sqlserver.SQLServerDriver
- Determine ROW that caused “unexpected end of file” error in BULK INSERT?
- Determine ROW that caused “unexpected end of file” error in BULK INSERT?
- The SELECT permission was denied on the object ‘Users’, database ‘XXX’, schema ‘dbo’
- How do you open an SDF file (SQL Server Compact Edition)?
- Conversion failed when converting the varchar value ‘simple, ‘ to data type int
- Must declare the scalar variable
- Exclude a column using SELECT * [except columnA] FROM tableA?
- Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 4 (Year)
- Trouble Connecting to sql server Login failed. “The login is from an untrusted domain and cannot be used with Windows authentication”
- Bulk load data conversion error (truncation)
- Difference between database and schema
- ‘Microsoft.ACE.OLEDB.16.0’ provider is not registered on the local machine.
- How do I fix the multiple-step OLE DB operation errors in SSIS?
- SQL Server: Error converting data type nvarchar to numeric
- SQL – WHERE (X, Y) IN (A, B)
- SQL Server Linked Server Example Query
- SQL “select where not in subquery” returns no results
- Format number as percent in MS SQL Server
- Can I use multiple “with”?
- Errors: “INSERT EXEC statement cannot be nested.” and “Cannot use the ROLLBACK statement within an INSERT-EXEC statement.” How to solve this?
- How to connect to a local database in SQL Server Management Studio?
- How to calculate age (in years) based on Date of Birth and getDate()
- Text was truncated or one or more characters had no match in the target code page including the primary key in an unpivot
- Arithmetic overflow error converting varchar to data type numeric. ’10’ <= 9.00
- What are named pipes?
- “select * into table” Will it work for inserting data into existing table
- Update query using Subquery in Sql Server
- Using Excel VBA to run SQL query
- Pad a string with leading zeros so it’s 3 characters long in SQL Server 2008
- How to connect to database from Unity