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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Datepart issues..

Author  Topic 

Ohfrikenno
Starting Member

1 Post

Posted - 2007-10-19 : 20:52:31
So I'm working on an assignment for school which asks me to return all orders made in the month of October. Normally I would go about that doing something like this...

SELECT *
FROM Orders
WHERE DATEPART(m, [OrderDate]) = 10

However, apparently it's done differently in SQL server 2005, which I just started using, I searched in help and thought it might go something like this..

SELECT *, DATEPART (m, 10)
FROM Orders

However...that returns ALL fields..so I thought I would have to specify the field I want it to check the date for..but I've tried a number of ways and nothing seems to work, any ideas?

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-10-19 : 22:50:59
Datepart function doesn't change in sql2k5, same usage as in sql2k.
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2007-10-20 : 04:39:14
SELECT * FROM Orders WHERE DATEPART(m, [OrderDate]) = 10
can also be done as:
SELECT * FROM Orders WHERE
month(OrderDate) = 10

which is ok for 2000 and 2005


With the second statement I can't see how you are filtering on DATEPART(m, [OrderDate])


Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page
   

- Advertisement -