SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Date Comparison Error


Date Comparison Error

Author
Message
dipanshu.mittal
dipanshu.mittal
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 Visits: 14
Dear All,

Greetings!!!!

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 comparison and help me out...

Note :- DNCDate Column's Max Value is 2nd Oct 2012, which need to pulled out in our query
laurie-789651
laurie-789651
SSChasing Mays
SSChasing Mays (616 reputation)SSChasing Mays (616 reputation)SSChasing Mays (616 reputation)SSChasing Mays (616 reputation)SSChasing Mays (616 reputation)SSChasing Mays (616 reputation)SSChasing Mays (616 reputation)SSChasing Mays (616 reputation)

Group: General Forum Members
Points: 616 Visits: 1272
Cannot see any problem with this. Can you look at supplied code & explain how yours differs.

Thanks



--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 comparison and help me out...

--Note :- DNCDate Column's Max Value is 2nd Oct 2012, which need to pulled out in our query

--=========== TEST DATA ================

declare @a as table ( DNCDATE DateTime );
insert @a values ( '26 Sep 2012 12:00:00' );
insert @a values ( '27 Sep 2012 12:00:00' );
insert @a values ( '28 Sep 2012 12:00:00' );
insert @a values ( '29 Sep 2012 00:00:00' );
insert @a values ( '29 Sep 2012 01:00:00' );
insert @a values ( '29 Sep 2012 12:00:00' );
insert @a values ( '29 Sep 2012 23:59:59' );
insert @a values ( '30 Sep 2012 12:00:00' );
insert @a values ( '02 Oct 2012 12:00:00' );

--======== QUERY =========

select * from @a
where DNCDATE>='29 Sep 2012';

--======== RESULTS ============
/*
DNCDATE
-----------------------
2012-09-29 00:00:00.000
2012-09-29 01:00:00.000
2012-09-29 12:00:00.000
2012-09-29 23:59:59.000
2012-09-30 12:00:00.000
2012-10-02 12:00:00.000

(6 row(s) affected)
*/



Are you using equals:



-- Are you using equals:
select * from @a
where DNCDATE='29 Sep 2012';
-- This doesn't work because the data type DateTime includes the time.

-- This will work though:
select * from @a
where DNCDATE >= '29 Sep 2012' AND DNCDATE < '30 Sep 2012';



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search