Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
how to compare date ? for example, I want to delete all records in April, 2006 . effective type is datetime. Do we have a simpler way to do this ?Thanks
delete from Price p where DATEPART(YEAR, p.effective) = 2006 and DATEPART(MONTH, p.effective) = 4
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts
Posted - 2012-01-11 : 10:25:41
It may be more efficient to do it like this:
delete from Price where effective >= '20060401' and effective < '20060501';
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2012-01-11 : 11:18:27
If you've index on effective field try to use Sunita's suggestion as it has more chances of using index compared to yours as you're applying function over column which will make it non-sargable------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
X002548
Not Just a Number
15586 Posts
Posted - 2012-01-11 : 11:23:34
quote:Originally posted by java148 how to compare date ? for example, I want to delete all records in April, 2006