General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Just wrote my first SP. Would like some advice for having a computed field of running balance in the below code
if exists (select * from sysobjects where id = object_id('dbo.getled6') and sysstat & 0xf = 4)
drop procedure dbo.getled6
GO
CREATE PROCEDURE getled6
@ledcode varchar(10),
@fromdate datetime,
@TODATE DATETIME
AS
CREATE TABLE #db_ledger (
glcd char (10) ,
gldt datetime ,
glfl char (8) ,
glblno char (10) ,
glblsrno char (5) ,
glamnt numeric(18, 2) ,
gltrcd char (10) NULL ,
matched numeric(18, 2) ,
balance numeric(18, 2) ,
glnarr varchar (255)
)
insert into #db_ledger (glcd,gldt,glfl,glblno,glblsrno,glamnt,glnarr)
select glcd, gldt=@fromdate, glfl = "OPENING",glblno='',glblsrno='',GLAMNT = SUM(GLAMNT) ,"Opening Balance"
from genled where glcd = @LEDcode
and gldt < @fromdate
GROUP by glCD
insert into #db_ledger
SELECT *
FROM GENLED
WHERE GLCD = @LEDCODE AND GLDT >=@FROMDATE AND GLDT <= @TODATE
ORDER BY GLDT
select * from #db_ledger
GO
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only