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

Need Help On this Query

$
0
0

Hi,

 

 

I'm using this query for generating a simple outstanding report.But im getting the "Out Standing Amount" is multiplied  according to the number of items in the document.How can i avoid this issue?.If  the ar invoice has two items  outstanding amount is doubled if the invoice has 3 items outstanding amount become triple.

 

 

 

 

DECLARE @Date AS DATETIME

DECLARE @Series AS varchar(30)

DECLARE @Branch AS varchar(30)

DECLARE @Exec AS varchar(30)

 

/* SELECT FROM [dbo].[OINV] S0 WHERE */ SET  @Date = /* S0.DocDate*/ '[%0]'

/* SELECT FROM [dbo].[NNM1] S2 WHERE */ SET  @Series = /* S2.SeriesName*/ '[%2]'

/* SELECT FROM [dbo].[OLCT] S3 WHERE */ SET  @Branch = /* S3.Location*/ '[%3]'

/* SELECT FROM [dbo].[OSLP] S4 WHERE */ SET  @Exec = /* S4.SlpName*/ '[%4]'

 

if( @Exec ='') set @Exec ='%'

if( @Series ='') set @Series ='%'

if( @Branch ='') set @Branch ='%'

if( @Date ='') set @Date =GETDATE()

 

Select distinct OINV.CardName [Customer Name], ISNULL(NNM1.SeriesName ,'-')+'/'+ CAST(OINV.DocNum as varchar) [Bill No.],

OINV.DocDate [Bill Date],INV1.Dscription,

OINV.DocTotal - OINV.PaidToDate [Out Standing Amount],

DATEDIFF(dd,OINV.DocDate,@Date)[No of Days]  from OINV

inner join INV1 on OINV.DocEntry = INV1.DocEntry

inner join OLCT on INV1.LocCode = OLCT.Code

inner join NNM1 on OINV.Series = NNM1.Series

inner join OSLP on OINV.SlpCode = OSLP.SlpCode 

where OINV.DocType ='I' and (OINV.DocTotal - OINV.PaidToDate)>0

and NNM1.SeriesName like @Series and OINV.DocDate<= @Date

and OLCT.Location like @Branch and OSLP.SlpName like @Exec


Viewing all articles
Browse latest Browse all 8995

Trending Articles



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