SELECT FOR UPDATE with SQL Server

Recently I had a deadlock problem because Sql Server locks more then necessary (page). You can’t really do anything against it. Now we are catching deadlock exceptions… and I wish I had Oracle instead. Edit: We are using snapshot isolation meanwhile, which solves many, but not all of the problems. Unfortunately, to be able to … Read more

Disadvantages of MARS (Multiple Active Result Sets)?

There are apparently at least two known (potential) drawbacks (from this (1) Team blog): Obviously this can cause potential problems for any legacy systems which weren’t designed to run against a MARS enabled design – “existing code optimized to run in the non-MARS world may show a slight performance dip when run un-modified with MARS” … Read more

Rounding SQL DateTime to midnight

In SQL Server 2008 and newer you can cast the DateTime to a Date, which removes the time element. WHERE Orders.OrderStatus=”Shipped” AND Orders.ShipDate >= (cast(GETDATE()-6 as date)) In SQL Server 2005 and below you can use: WHERE Orders.OrderStatus=”Shipped” AND Orders.ShipDate >= DateAdd(Day, Datediff(Day,0, GetDate() -6), 0)

Simple DateTime sql query

You missed single quote sign: SELECT * FROM TABLENAME WHERE DateTime >= ’12/04/2011 12:00:00 AM’ AND DateTime <= ’25/05/2011 3:53:04 AM’ Also, it is recommended to use ISO8601 format YYYY-MM-DDThh:mm:ss.nnn[ Z ], as this one will not depend on your server’s local culture. SELECT * FROM TABLENAME WHERE DateTime >= ‘2011-04-12T00:00:00.000’ AND DateTime <= ‘2011-05-25T03:53:04.000’