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 |
|
Exir
Posting Yak Master
151 Posts |
Posted - 2008-10-20 : 03:34:48
|
What is the problem with this code? I think it should enter the contain of CompNum column into Turn column. but it just insert 0 for all rows of Turn column.Is there any problem in my code?set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgoALTER PROCEDURE [dbo].[SetTurn3]ASBEGINDECLARE @Num intDECLARE SetTurn CURSOR FORSELECT CompNum FROM RegOPEN SetTurnFETCH NEXT FROM SetTurn INTO @NumWHILE @@FETCH_STATUS= 0BEGINUpdate Reg SET Turn=@NumFETCH NEXT FROM SetTurn INTO @NumENDCLOSE SetTurn END |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-20 : 03:53:41
|
| What are you trying to do with this cursor?MadhivananFailing to plan is Planning to fail |
 |
|
|
Exir
Posting Yak Master
151 Posts |
Posted - 2008-10-20 : 04:10:45
|
| I wrote it to read one field of table, row by row(CompNum field) and transfer it to Num parameter(FETCH NEXT FROM SetTurn INTO @Num). then for observe what is in num, i wrote this code to transfer what is in Num to other field(Turn)(Update Reg SET Turn=@Num). so what is in Turn field should be the same as CompNum field but it fill all by 0 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-20 : 04:15:36
|
seems like what you want is thisUpdate Reg SET Turn=CompNum |
 |
|
|
Exir
Posting Yak Master
151 Posts |
Posted - 2008-10-20 : 05:11:18
|
| No, i want to see how cursor works and i have written it for this purpose |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-20 : 06:17:30
|
quote: Update Reg SET Turn = @Num
This statement updates all records in reg table since there is no WHERE clause.And when you do, the cursor fails since if no longer has same information as it started with.Add a WHERE clause or add a WHERE CURRENT OF clause. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|