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

Re: Help me finish my query - please ;)

$
0
0

Hi,

 

Here is the query thus far:

 

Declare @FromDate Datetime

Declare @ToDate Datetime

declare @Slp as nvarchar(20)

Set @FromDate = (Select min(t0.Docdate) from dbo.ORDR t0 where t0.Docdate >='[%1]')

Set @ToDate = (Select max(t0.Docdate) from dbo.ORDR t0 where t0.Docdate <='[%2]')

set @slp = (select max(T2.[SlpName]) from OSLP t2 where T2.[SlpName] = '[%3]')

 

 

Select [C] as Customercode, [D] as Customername,[S] as SalesEmp, [EDI],[EMAIL],[FAX],[HEAD OFFICE],[MAJOR],[MINISELL],[OPEN SHOWROOM],[PHONE],[STAFFPURCHASE],[TRADEFAIR],[WEBSITE]

from

(

 

 

SELECT T0.[CardCode] as C, t0.cardname as  D, T1.[SlpName] as S,sum(T0.[DocTotal]) as T, T0.[U_OrderSource] as P FROM ORDR T0  INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode WHERE T0.[DocDate] between @fromdate and @todate and  T1.[SlpName]  = @Slp  GROUP BY T0.[CardCode], T1.[SlpName],T0.[U_OrderSource], t0.cardname ) S

Pivot

(sum(t) FOR P in ([EDI],[EMAIL],[FAX],[HEAD OFFICE],[MAJOR],[MINISELL],[OPEN SHOWROOM],[PHONE],[SyTAFFPURCHASE],[TRADEFAIR],[WEBSITE])) P

 

Your help to add the final column is appreciated.


Regards

Rick


Viewing all articles
Browse latest Browse all 8451

Trending Articles



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