IamAzhar says:
SELECT
ROW_NUMBER() OVER (
ORDER
BY
(CustomerID)) CustomerID
,
''
as
PreviousAmount
,
Date
,
ISNULL
(SellAmount,0)
as
SellAmount
,
Isnull
(CreditAmount,0)
as
CreditAmount
,
Isnull
(discount,0)
as
discount
,
ISNULL
(CreditAmount+discount,0)
as
Total
,Descrip
FROM
tempSellCredit
Change with below query and check.
SELECT CustomerID,((SUM(Total)+ISNULL(CreditAmount,0))-ISNULL(SellAmount,0)),
Date,SellAmount,CreditAmount,discount,Total,Descrip
FROM (
SELECT ROW_NUMBER() OVER (ORDER BY (CustomerID)) CustomerID
,'' as PreviousAmount
,Date
,ISNULL(SellAmount,0)as SellAmount
,Isnull(CreditAmount,0) as CreditAmount
,Isnull(discount,0)as discount
,ISNULL(CreditAmount+discount,0) as Total
,Descrip
FROM tempSellCredit
) a