Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Where clause

Author  Topic 

OWSQL
Starting Member

27 Posts

Posted - 2011-11-24 : 05:43:22
Hi
I have a table where a column "begtime" is defined as datatype "datetime". I need to update another column based on the value in begtime but for some reason I cannot update this because my where clause cannot find the column value.

This is just a test query which I run on the table below. No matter what I write in the like '2011-11-01....' I get nothing. Many other updates in the same table works fine, so I think it is due to some datatype mismatch? Any ideas?

select * from dbo.Stresstest_Relative_FutSwaps
where begtime like '2011-11-01%'


product tradetype begtime qty gns_price Unit New_qty
HS Rtdm 3.5% FOB Barges Swap Exchange 2011-11-01 00:00:00.000 -4000 559,85147 mt -4000
HS Rtdm 3.5% FOB Barges Swap Exchange 2011-11-01 00:00:00.000 10000 631,875 mt 10000
HS Rtdm 3.5% FOB Barges Swap OTC 2011-11-01 00:00:00.000 -9005 577,047149 mt -9005
HS Rtdm 3.5% FOB Barges Swap Exchange 2011-12-01 00:00:00.000 1000 574,437804 mt 1000
HS Rtdm 3.5% FOB Barges Swap OTC 2011-12-01 00:00:00.000 -4025 584,361781 mt -4025
HS Rtdm 3.5% FOB Barges Swap Exchange 2012-01-01 00:00:00.000 3000 601,668831 mt 3000

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2011-11-24 : 05:46:22
select * from dbo.Stresstest_Relative_FutSwaps
where begtime = '2011-11-01'

This should work.

If you want a range, use > and <=

or you could use BETWEEN if there are no nulls.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-11-24 : 06:14:27
Also make sure to use unambigious date formats
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/03/understanding-datetime-column-part-ii.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -