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

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Alternate way of using cursor for this

Author  Topic 

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2010-04-21 : 05:43:24
Hi experts,

can you please provide me the solution of an alternate way of using curosor here..please seee below code..


DECLARE @cPRPCOD VARCHAR(20), @cROMTYP VARCHAR(3),@cFRMDAT INT,@cTOODAT INT,@cFTRSGL NUMERIC(20,5)

DECLARE CUR CURSOR FOR
SELECT TTB.PRPCOD,TTB.ROMTYP,TTB.FRMDAT,TTB.TOODAT,TTB.TBLTYP,TTB.FTRSGL
FROM HSTTBTBL TTB
WHERE TTB.TBLTYP = 'R' AND ISNULL(TTB.PACCOD,0) = 0
ORDER BY TTB.PRPCOD,TTB.ROMTYP,TTB.TBLTYP,TTB.FRMDAT
OPEN CUR
FETCH NEXT FROM CUR INTO @cPRPCOD,@cROMTYP,@cFRMDAT,@cTOODAT,@TBLTYP,@cFTRSGL
WHILE @@FETCH_STATUS = 0
BEGIN
update avl set avl.FTRSGL = @cFTRSGL
FROM #ALLAVLROOMTYPE AVL
where AVL.RUNDAT between @cFRMDAT and @cTOODAT
AND AVL.PRPCOD = @cPRPCOD AND AVL.ROMTYP = @cROMTYP

FETCH NEXT FROM CUR INTO @cPRPCOD,@cROMTYP,@cFRMDAT,@cTOODAT,@TBLTYP,@cFTRSGL
END
CLOSE CUR
DEALLOCATE CUR

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-21 : 05:50:03
Maybe this:

update avl
set avl.FTRSGL = dt.FTRSGL
FROM #ALLAVLROOMTYPE AVL
join
(SELECT TTB.PRPCOD,TTB.ROMTYP,TTB.FRMDAT,TTB.TOODAT,TTB.TBLTYP,TTB.FTRSGL
FROM HSTTBTBL TTB
WHERE TTB.TBLTYP = 'R' AND ISNULL(TTB.PACCOD,0) = 0)dt
on AVL.RUNDAT between dt.FRMDAT and dt.TOODAT AND
AVL.PRPCOD = dt.PRPCOD AND
AVL.ROMTYP = dt.ROMTYP



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-21 : 06:03:48
[code]update avl set avl.FTRSGL = t.FTRSGL
FROM #ALLAVLROOMTYPE AVL
JOIN (SELECT TTB.PRPCOD,TTB.ROMTYP,TTB.FRMDAT,TTB.TOODAT,TTB.TBLTYP,TTB.FTRSGL
FROM HSTTBTBL TTB
WHERE TTB.TBLTYP = 'R' AND ISNULL(TTB.PACCOD,0) = 0 ) t
ON AVL.RUNDAT between t.FRMDAT and t.TOODAT
AND AVL.PRPCOD = t.PRPCOD AND AVL.ROMTYP = t.ROMTYP
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-21 : 06:04:24
ah...forgot to refresh


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2010-04-21 : 06:09:27
Thank you very much for both of you..

Thanks once agian to Webfred and Visakh
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-21 : 06:10:33
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-21 : 07:30:03
quote:
Originally posted by haroon2k9

Thank you very much for both of you..

Thanks once agian to Webfred and Visakh


welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -