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 2012 Forums
 Transact-SQL (2012)
 Why does this select statement multiply by 100?

Author  Topic 

MelissaTsalicoglou
Starting Member

16 Posts

Posted - 2014-06-05 : 07:13:08
Select Year(orderdate) * 100 + MONTH(orderdate) as yearmonthno,
SUM(d.qty * d.unitprice) as salesamountpermonth
From Sales.Orders as o
Inner join Sales.Orderdetails as d on d.orderid = o .orderid
Group BY Year(orderdate), Month(orderdate)
Order by yearmonthno;

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2014-06-05 : 07:17:08
let's say orderdate is today ie. 2014_06_05

year(orderdate) gives 2014
month(orderdate) gives 6
addition would give 2020 but needed is 201406
this is why 2014 * 100 is used
so we have 201400 + 6 give 201406



Too old to Rock'n'Roll too young to die.
Go to Top of Page
   

- Advertisement -