SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 simple date compare problem
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mike13
Posting Yak Master

Netherlands
214 Posts

Posted - 05/10/2013 :  07:29:59  Show Profile  Click to see mike13's MSN Messenger address  Reply with Quote
Hi all,

I want to a select:

SELECT @counter=COUNT(shipdate) FROM T_Order_Main
WHERE OrderID = @Ordernr AND Shipdate = '01-01-1900 00:00:00'
Shipdate (datetime) in the DB has this value '01-01-1900 00:00:00'
but when i try the above statement it

any idea how to solve this?

visakh16
Very Important crosS Applying yaK Herder

India
52323 Posts

Posted - 05/10/2013 :  07:45:52  Show Profile  Reply with Quote
is shipdate of type datetime?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3712 Posts

Posted - 05/10/2013 :  09:25:36  Show Profile  Reply with Quote
quote:
Originally posted by mike13

Hi all,

I want to a select:

SELECT @counter=COUNT(shipdate) FROM T_Order_Main
WHERE OrderID = @Ordernr AND Shipdate = '01-01-1900 00:00:00'
Shipdate (datetime) in the DB has this value '01-01-1900 00:00:00'
but when i try the above statement it

any idea how to solve this?

Don't know if it is my firewall causing the problem, but your posting reads as "but when i try the above statement it". What happens when you try the statement? Error message? No rows returned?

If you don't see any rows in the output, add another statement to select the value of @counter:
SELECT @counter=COUNT(shipdate) FROM T_Order_Main 
WHERE OrderID = @Ordernr AND Shipdate = '01-01-1900 00:00:00'

SELECT @counter;
Go to Top of Page

mike13
Posting Yak Master

Netherlands
214 Posts

Posted - 05/10/2013 :  09:35:41  Show Profile  Click to see mike13's MSN Messenger address  Reply with Quote
value of the counter is always 0 even if the it exists.

yes it is datetime
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3712 Posts

Posted - 05/10/2013 :  10:02:47  Show Profile  Reply with Quote
See if this returns any rows:
SELECT * FROM T_Order_Main 
WHERE OrderID = @Ordernr AND Shipdate = '19000101'
If it does not return any rows, run the following query, use the OrderId you get from that to set the value of @ordernr and then try again
SELECT TOP 1 OrderID FROM T_Order_Main  WHERE Shipdate = '19000101'
Go to Top of Page

mike13
Posting Yak Master

Netherlands
214 Posts

Posted - 05/11/2013 :  13:09:47  Show Profile  Click to see mike13's MSN Messenger address  Reply with Quote
Thanks a lot.

Fault was mine. seems i had code (vb.net) that did some changes to the table before this SP
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000