web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Real Life Dynamics User (RLDU) / SQL Scripts–Order Count–Pre...

SQL Scripts–Order Count–Previous Week By User

Ron Wilson Profile Picture Ron Wilson 6,010

Do you ever wonder what your sales order workload looks like for you customer service staff?  This script will show you the number of orders entered by user for last week.

***Note that you will need to make sure the @doc_date is set to January 1st of the current year***

This script uses the following views:

– Open Sales Documents (tspvSalesDocument)

Historical Sales Documents (tspvSalesDocuementHistory)

DECLARE @doc_date DATETIME

–Set @doc_date to January 1st of the current year–
SET @doc_date = ‘1/1/2011’

SELECT  created_by,
        [Week] = DATEPART(ww, doc_date),
        [Orders_Entered] = COUNT(*)
FROM    ( select    Created_By,
                    Doc_Date
          from      tspvSalesDocumentHistory
          WHERE     Doc_Date >= @doc_date
                    AND Sales_Doc_Type = ‘order’
                    AND Original_Num = ”
          union all
          select    Created_By,
                    Doc_Date
          FROM      tspvSalesDocument
          WHERE     Doc_Date >= @doc_date
                    AND Sales_Doc_Type = ‘order’
                    AND Original_Num = ”
        ) as combined
        WHERE DATEPART(ww,combined.Doc_Date) = DATEPART(ww,GETDATE()-7)
GROUP BY Created_By,
        DATEPART(ww, doc_date)
ORDER BY DATEPART(ww, Doc_Date),
        Created_By


This was originally posted here.

Comments

*This post is locked for comments