General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Is this the correct procedure. This does not return a result set.
CREATE PROCEDURE getled7
@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
DECLARE LED_CURSOR CURSOR
FOR (select * from #db_ledger)
FOR UPDATE
OPEN LED_CURSOR
DECLARE
@RUNBAL NUMERIC(18,2)
FETCH NEXT FROM LED_CURSOR
select @runbal = 0.00
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
UPDATE #db_ledger SET balance = @runbal+glamnt where current of led_cursor
UPDATE #db_ledger SET @runbal = balance where current of led_cursor
END
FETCH NEXT FROM LED_CURSOR
END
close led_cursor
DEALLOCATE led_cursor
SELECT * FROM #DB_LEDGER
GO
Previous
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