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.
| Author |
Topic |
|
tedew
Starting Member
22 Posts |
Posted - 2005-11-09 : 15:39:25
|
| hello:)I have a problem with building cursor:(I have a table : tblDataand there are 3 recordsI want to list them trought cursor this is my code --------------------------------------DECLARE @data varchar(50)declare C1 cursor for Select id from tblWykladowcaopen C1 FETCH NEXT FROM C1 into @datawhile @@FETCH_STATUS =0begin SELECT @dataendclose C1DEALLOCATE C1but this cursor works,works,works .... almost 3000 recordc and still works and there are only 3 records in the table .????bye,sorry for my english |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-11-09 : 15:50:44
|
why do you want to use a cursor? why not just use a SELECT?select id from tblWykladowca the problem with your cursor is you didn't put another "fetch next" inside the while loop.Be One with the OptimizerTG |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
tedew
Starting Member
22 Posts |
Posted - 2005-11-10 : 03:36:33
|
| hello:)I know that I can use "Select" to list all records in my table :) this is very simple cursor - I'm learning now this useful "function" in T-SQL :) @TGthanks for your help - it's working now :)bye |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2005-11-10 : 07:18:07
|
| Where did you get the idea that cursors are useful? Do yourself a favor, avoid cursors and learn SQL, you'll get a lot more out of it. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-10 : 07:21:10
|
>>Where did you get the idea that cursors are useful? May be he is trying to simulate Client side For or While loops in SQL MadhivananFailing to plan is Planning to fail |
 |
|
|
bridge
Yak Posting Veteran
93 Posts |
Posted - 2005-11-10 : 08:11:24
|
| Try after replacing this code with yourswhile @@FETCH_STATUS =0begin SELECT @dataFETCH NEXT FROM C1 into @dataend |
 |
|
|
|
|
|