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

Re: Query to get the a/r receivables based on a cut-off date

$
0
0

Hi,

 

Try this:

 

eclare @Cust as nvarchar(20)
Declare @FromDate Datetime
Declare @ToDate Datetime
declare @Group as nvarchar(20)
set @cust = (select max(t0.cardcode) from OINV t0 where t0.cardcode = '[%0]')
Set @FromDate = (Select min(t0.Docdate) from dbo.OINV t0 where t0.Docdate >='[%1]')
Set @ToDate = (Select max(t0.Docdate) from dbo.OINV t0 where t0.Docdate <='[%2]')
set @group = (select max(t2.groupname) from OCRG t2 where t2.groupname = '[%3]')

SELECT [CustName] as CustName, [G] as CustGroup,[1] as Jan,[2] as Feb,[3] as Mar,[4] as April,[5] as May,[6] as June,[7] as July,[8] as Aug,[9] as Sept,[10] as Oct,[11] as Nov,[12] as Dec


from
(SELECT T0.[CardName] as CustName, sum(T0.[DocTotal]) as Total, datepart(mm,T0.[DocDate]) as week, t2.groupname as G  FROM OINV T0   left JOIN OCRD T1 ON T0.CardCode = T1.CardCode left JOIN OCRG T2 ON T1.GroupCode = T2.GroupCode   WHERE year(T0.[DocDate]) = 2013 and T0.[CardCode] = @Cust and  T0.[DocStatus]  ='o' and T0.[DocDate] between @fromdate and @todate and t2.groupname = @group GROUP BY T0.[CardName],T0.[DocDate],t2.groupname

union all
(SELECT T0.[CardName] as CustName, -sum(T0.[DocTotal]) as Total, datepart(mm,T0.[DocDate]) as week,t2.groupname as G  from ORIN T0  left JOIN OCRD T1 ON T0.CardCode = T1.CardCode left JOIN OCRG T2 ON T1.GroupCode = T2.GroupCode   WHERE year(T0.[DocDate]) = 2013 and T0.[CardCode] = @Cust and  T0.[DocStatus]  ='o' and T0.[DocDate] between @fromdate and @todate and t2.groupname = @group  GROUP BY T0.[CardName],T0.[DocDate],t2.groupname )) S

Pivot
(sum(S.total) For WEEK IN ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P

 

Thanks & Regards,

Nagarajan


Viewing all articles
Browse latest Browse all 8944

Trending Articles



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