Today I face a problem in Date Comparison please help me in out thanks in advance... problem mention below:-
In my Table there is a Column Named DNCDATE, format of this Column is DateTime. when i pass a varchar type date then it will not compute any output. e.g DNCDATE>='29 Sep 2012' when i cast the column then it will give me output but it will take longer time to compute the result e.g. CAST( DNCDATE as DATE)>='29 Oct 2012'..
Please guide me about the date compaison and help me out...
Use the YYYYMMDD format. So for 29, Sept 2012, you would use:
DNCDATE>='20120929'
YYYYMMDD is an unambiguous format - i.e., it will be interpreted correctly regardless of regional or language settings. Don't use the other form that you were trying to use (CASTing the date to a string) - it is inefficient, and not recommended for other reasons as well.
Today I face a problem in Date Comparison please help me in out thanks in advance... problem mention below:-
In my Table there is a Column Named DNCDATE, format of this Column is DateTime. when i pass a varchar type date then it will not compute any output. e.g DNCDATE>='29 Sep 2012' when i cast the column then it will give me output but it will take longer time to compute the result e.g. CAST( DNCDATE as DATE)>='29 Oct 2012'..
Please guide me about the date compaison and help me out...
Also worth pointing out the concept of SARGable (Search-Argument-able). When you wrap a function around a column in a table, SQL Server cannot properly optimize the execution plan and use the best indexes.