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
 Issues with month() and datepart()

Author  Topic 

MTSkibum
Starting Member

1 Post

Posted - 2012-12-03 : 16:13:31
For ease of reading I am just going to post the select statement.

I have a sql that works just fine:

SELECT DISTINCT org.organization,
epi.item,
(NVL(net.xx_net_need, 0) * NVL(net.xx_conso_cost, 0)) Net_Need,
(NVL(net.proj_on_hand, 0) * NVL(net.xx_conso_cost, 0)) Projected_on_hand,
net.sales_date
FROM ..............

;


The problem is when i try to turn the date into a month or month/year.

This does not work:

SELECT DISTINCT org.organization,
epi.item,
(NVL(net.xx_net_need, 0) * NVL(net.xx_conso_cost, 0)) Net_Need,
(NVL(net.proj_on_hand, 0) * NVL(net.xx_conso_cost, 0)) Projected_on_hand,
month(net.sales_date)

This does not work either:

SELECT DISTINCT org.organization,
epi.item,
(NVL(net.xx_net_need, 0) * NVL(net.xx_conso_cost, 0)) Net_Need,
(NVL(net.proj_on_hand, 0) * NVL(net.xx_conso_cost, 0)) Projected_on_hand,
DATEPART(mm,net.sales_date)



I have verified that I am working with a date.

COLUMN_NAME DATA_TYPE NULLABLE
SALES_DATE DATE No

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-12-03 : 16:42:22
NVL() is an Oracle function, SQLTeam is a Microsoft SQL Server website. There's an Oracle forum over at http://dbforums.com/
Go to Top of Page
   

- Advertisement -