Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8511

Re: Query to list BP information and First Order Date

$
0
0

Hi Tim,

 

Try this:

 

SELECT T0.[CardCode], T0.[CardName], T3.SlpName, T0.[CreateDate], MIN(T1.[DocDate]) AS 'First Order', T2.Total AS '12 Month Total'


FROM OCRD T0 
INNER JOIN ORDR T1 
ON T0.CardCode = T1.CardCode
INNER JOIN (Select SUM(DocTotal) As 'Total', CardCode FROM ORDR WHERE DocDate>DATEADD(year,-1,GETDATE()) AND DocDate<GETDATE() GROUP BY CardCode) T2
ON T0.CardCode=T2.CardCode
INNER JOIN OSLP T3
ON T0.SlpCode=t3.SlpCode
WHERE CardType ='C'
GROUP BY T0.CardCode, T0.CardName,T3.SlpName, T0.[CreateDate], T2.Total

 

I tested that and it works moderately well.  If you want to break down the sales totals per month for the last twelve months, that would take a little tweaking.  As it stands, I just totalled the last 12 months of orders.

 

You might also want to format the create date and First Order dates as they appear in standard date format (meaning they give a useless time stamp as well.  Let me know if you have any problems.

 

Cheers,


Viewing all articles
Browse latest Browse all 8511

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>