Dear All,
I've this query which will results the outstanding value with no. of days.There is a 'series' column (NNM1.SeriesName ) in this query that i need to alter .Series always have 3 characters i need to split the characters into 3 column.That means my series is like 'CTG-15' (First character represents 'DB',second character represents 'location', 3rd character represents 'series', and no.' 15' represents 'year') .I need to split the value to separate columns as shown in the table below.
DB | LOCATION | SERIES | YEAR |
---|---|---|---|
C | T | G | 15 |
Query
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],oslp.slpname , ISNULL(NNM1.SeriesName ,'-') as 'series' ,CAST(OINV.DocNum as varchar) [Bill No.],
OINV.DocDate [Bill Date],INV1.Dscription,INV1.Quantity,INV1.Price,
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