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
 General SQL Server Forums
 New to SQL Server Programming
 How to pull date without time

Author  Topic 

tranquilraven
Starting Member

19 Posts

Posted - 2012-06-06 : 10:22:44
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
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-06-06 : 10:26:46
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
   

- Advertisement -