Wednesday, March 28, 2012

how to remove cursor ?`

declare @.oldchgcode nchar(20),@.chgcode nchar(20),@.tmpchgcode_branchid
nvarchar(50)
declare tmp cursor for select oldchgcode ,chgcode from
DTS_MASTER.dbo.chginfo
where oldchgcode is not null and oldchgcode <> chgcode order by oldchgcode
I can declare a cursor very well and run in the first time.
However, when I run the sec.times, it said, I had declare already.
How can I delete the cursor ?Hi, Agnes
You should close the cursor, then deallocate it. You can also use local
cursors, which deallocate themselves (when the scope in which they are
defined ends).
However, using cursors is generally a bad idea. Most tasks can be
solved more efficiently using set-based code (processing all the rows
in a single statement, instead of processing one row at a time).
Razvan|||DEALLOCATE CURSOR <cusrsorname>
Regards
Roji. P. Thomas
http://toponewithties.blogspot.com
"Agnes" <agnes@.dynamictech.com.hk> wrote in message
news:uV15Po%23SGHA.5828@.TK2MSFTNGP14.phx.gbl...
> declare @.oldchgcode nchar(20),@.chgcode nchar(20),@.tmpchgcode_branchid
> nvarchar(50)
> declare tmp cursor for select oldchgcode ,chgcode from
> DTS_MASTER.dbo.chginfo
> where oldchgcode is not null and oldchgcode <> chgcode order by oldchgcode
> I can declare a cursor very well and run in the first time.
> However, when I run the sec.times, it said, I had declare already.
> How can I delete the cursor ?
>
>sql

No comments:

Post a Comment