SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

tranquilraven
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 (

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3383 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  
 New 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.08 seconds. Powered By: Snitz Forums 2000