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
 General SQL Server Forums
 New to SQL Server Programming
 update problem

Author  Topic 

shubhada
Posting Yak Master

117 Posts

Posted - 2006-08-02 : 06:57:43
I have table with Colum key like

key
1
2
3
4
5
6

i want to update this column like as below

2
3
4
5
6
7

so I have write one proc


ALTER proc cm__update_test
as
begin

declare @TitleKey numeric(3,0)

declare cm_cursor cursor for

select key from Table
where key

open cm_cursor

fetch cm_cursor into @TitleKey

while @@fetch_status = 0
begin

update SecurityModule
set ModKey = ModKey + 1
FETCH next from cm_cursor into @TitleKey
end

close cm_cursor
deallocate cm_cursor

return
end


Please tell me where I am wrong
above proc is nopt working properly

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-08-02 : 07:02:42
you dont require cursor for this ..

update SecurityModule
set ModKey = ModKey + 1

I guess this should be fine for incrementing the column data by 1


Chirag
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2006-08-02 : 07:02:53
Don't use a cursor. simply
update SecurityModule set ModKey = ModKey + 1


For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2006-08-02 : 07:03:15


For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

shubhada
Posting Yak Master

117 Posts

Posted - 2006-08-02 : 07:21:13
but suppose i want to update key from 3
key
1
2
3
4
5
6

Result should be

1
2
4
5
6
7



SQLTeam
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-08-02 : 07:27:25
update SecurityModule
set ModKey = ModKey + 1
where modkey >= 3


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -