Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

 SQL Server Forums Profile | Active Topics | Members | Search | Forum FAQ
 All Forums  General SQL Server Forums  New to SQL Server Programming  Calculate balance Reply to Topic  Printer Friendly
Author  Topic

dinhson_vn
Starting Member

15 Posts

 Posted - 08/27/2013 :  09:24:09 I currently have 1 procedure:``` ALTER PROCEDURE [dbo].[sp_Support_Out_In_Detail] @No AS NVARCHAR(4000), @FromDate DATETIME, @ToDate DATETIME, @TransInvoiceID INT AS SELECT x.No,x.Name,x.ZIPCODE,x.FromDate,x.ToDate,x.Total450c, n.Total450k, x.Total24c, ISNULL(x.Total450c,0)-(ISNULL(n.Total450k,0)) TotalCheck450, /*-Save TotalCheck450 to calculate and compare--*/ ((x.Total24c)*1000) ATMTotalSupport24, CASE WHEN ISNULL(x.Total450c,0)-(ISNULL(n.Total450k,0)) <0 THEN x.Total450c*800 WHEN ISNULL(x.Total450c,0)-(ISNULL(n.Total450k,0)) >0 THEN n.Total450k*800 WHEN ISNULL(x.Total450c,0)-(ISNULL(n.Total450k,0)) =0 THEN x.Total450c*800 END ATMToatlSupport45 INTO #tmpSupportCost0003 FROM Tbl_AmountTranpost_Detail_Out x LEFT JOIN Tbl_AmountTranpost_Detail_In n ON n.No=x.No AND x.No = n.No WHERE x.No=@No AND CONVERT(NVARCHAR(10),x.FromDate,112) = CONVERT(NVARCHAR(10),@FromDate,112) AND CONVERT(NVARCHAR(10),x.ToDate,112) = CONVERT(NVARCHAR(10),@ToDate,112) --AND x.No=b.No /*--Update Data --*/ INSERT INTO Tbl_SupportCost (No ,Name ,ZIPCODE ,FromDate ,ToDate ,Total450c ,Total450k ,Total24c ,TotalCheck450 ,ATMTotalSupport24 ,ATMToatlSupport45 ,IsDelete ,CreateDate ,TransInvoiceID) SELECT @No ,Name ,ZIPCODE ,@FromDate ,@ToDate ,Total450c ,Total450k ,Total24c ,TotalCheck450 ,ATMTotalSupport24 ,ATMToatlSupport45 ,0 ,GETDATE() ,@TransInvoiceID FROM #tmpSupportCost0003 DROP TABLE #tmpSupportCost0003 ```Table save Totalcheck450 is structured as follows: Now when the next month, I want to n.Total450k + Totalcheck-01/2013: ISNULL (x.Total450c, 0) - (ISNULL (n.Total450k, 0)) TotalCheck450 = A (A number will be saved, TotalCheck450)-02/2013: ISNULL (x.Total450c, 0) - (ISNULL (n.Total450k, 0)) TotalCheck450here A number would be : A + (ISNULL (n.Total450k, 0)- What can I do to get results ?Looking forward to the help from everyoneI thank you very much.

dinhson_vn
Starting Member

15 Posts

 Posted - 08/27/2013 :  10:19:09 You do not understand, I will answer. and send the illustrations.Thanks. Edited by - dinhson_vn on 08/27/2013 10:27:59

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

 Posted - 08/28/2013 :  02:36:29 looks like you need a running count. see scenario 1 belowhttp://visakhm.blogspot.in/2010/01/multipurpose-apply-operator.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs

dinhson_vn
Starting Member

15 Posts

 Posted - 08/28/2013 :  03:31:16 quote:Originally posted by visakh16looks like you need a running count. see scenario 1 belowhttp://visakhm.blogspot.in/2010/01/multipurpose-apply-operator.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogsNot youThe number of shipments is AB (out put)The number of returns is AC (input) Calculate the number of AC-ABI will have 1 ABC figures:If the ABC <= 0 the AC * 800If the ABC > 0 then ABC * 800Here is what the procedure was done.Now if the AC-AB> 0 then saved the ABCABC will be added to the AC of the following monthABC + AC will be added next month

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

 Posted - 08/28/2013 :  12:19:11 quote:Originally posted by dinhson_vnquote:Originally posted by visakh16looks like you need a running count. see scenario 1 belowhttp://visakhm.blogspot.in/2010/01/multipurpose-apply-operator.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogsNot youThe number of shipments is AB (out put)The number of returns is AC (input) Calculate the number of AC-ABI will have 1 ABC figures:If the ABC <= 0 the AC * 800If the ABC > 0 then ABC * 800Here is what the procedure was done.Now if the AC-AB> 0 then saved the ABCABC will be added to the AC of the following monthABC + AC will be added next monthI cant correlate your explanation with earlier posted output Can you explain with relation to that------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs

dinhson_vn
Starting Member

15 Posts

 Posted - 08/28/2013 :  22:43:27 quote:I cant correlate your explanation with earlier posted output Can you explain with relation to that------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogsFor exampleHope you can helpThanks Edited by - dinhson_vn on 08/28/2013 22:55:18

dinhson_vn
Starting Member

15 Posts

 Posted - 08/29/2013 :  09:02:46 Help Me !!!Thanks.
Topic
 Reply to Topic  Printer Friendly Jump To: Select Forum General SQL Server Forums       New to SQL Server Programming       New to SQL Server Administration       Script Library       Data Corruption Issues       Database Design and Application Architecture SQL Server 2012 Forums       Transact-SQL (2012)       SQL Server Administration (2012)       SSIS and Import/Export (2012)       Analysis Server and Reporting Services (2012)       Replication (2012)       Availability Groups and DR (2012)       Other SQL Server 2012 Topics SQL Server 2008 Forums       Transact-SQL (2008)       SQL Server Administration (2008)       SSIS and Import/Export (2008)       High Availability (2008)       Replication (2008)       Analysis Server and Reporting Services (2008)       Other SQL Server 2008 Topics SQL Server 2005 Forums       Transact-SQL (2005)       SQL Server Administration (2005)       .NET Inside SQL Server (2005)       SSIS and Import/Export (2005)       Service Broker (2005)       Replication (2005)       High Availability (2005)       Analysis Server and Reporting Services (2005)       Express Edition and Compact Edition (2005)       Other SQL Server Topics (2005) SQL Server 2000 Forums       SQL Server Development (2000)       SQL Server Administration (2000)       Import/Export (DTS) and Replication (2000)       Transact-SQL (2000)       Analysis Services (2000)       MSDE (2000) Development Tools       ASP.NET       Reporting Services Development       Other Development Tools Site Related Forums       Site Related Discussions       Article Discussion       Poll Discussion       The Yak Corral Other Forums       SQL Server 6.5 \ SQL Server 7.0       Other Topics       MS Access       ClearTrace Support Forum Old Forums       CLOSED - General SQL Server       CLOSED - SQL Server 2005/Yukon  -------------------- Home Active Topics Frequently Asked Questions Member Information Search Page
 SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC