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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to pull date without time
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

19 Posts

Posted - 06/06/2012 :  10:22:44  Show Profile  Reply with Quote
I want to use just the month in an IN statement. Basically what I am trying to do is sort the data by month. I can break down the Date as Month/Day/Year but can't seem to get just the month to be returned. Any help would be appreciated. I am learning much here I hope I don't become a bother.

SELECT convert(varchar(10),o.OrderDate,101) AS 'Date', od.ProductCode AS 'Item Number', od.ProductName AS 'Item Description', '$' + CONVERT(varchar(12),  od.ProductPrice , 1)AS 'Item Price',  '$' + CONVERT(varchar(12),  o.salestax1 , 1) AS Tax,  '$' + CONVERT(varchar(12),  o.TotalShippingCost, 1) AS 'Shipping and Handling', '$' + CONVERT(varchar(12),od.ProductPrice+o.salestax1+o.TotalShippingCost, 1) AS 'Net Invoice Amount' 
FROM Orders AS o
INNER JOIN OrderDetails AS od ON o.OrderID = od.OrderIDWHERE convert(varchar(10),o.OrderDate,101) IN (

Flowing Fount of Yak Knowledge

United Kingdom
3385 Posts

Posted - 06/06/2012 :  10:26:46  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
month(dte) will return the month.
month(dte) in (1,5,7)

You maybe want year, month?
best to work with style 112 which is yyyymmdd
convert(varchar(6),dte,112) in ('201201', 201203')

Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000