SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 update problem
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shubhada
Posting Yak Master

India
117 Posts

Posted - 08/02/2006 :  06:57:43  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
1907 Posts

Posted - 08/02/2006 :  07:02:42  Show Profile  Visit chiragkhabaria's Homepage  Send chiragkhabaria a Yahoo! Message  Reply with Quote
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
Flowing Fount of Yak Knowledge

2161 Posts

Posted - 08/02/2006 :  07:02:53  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

2161 Posts

Posted - 08/02/2006 :  07:03:15  Show Profile  Reply with Quote


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

India
117 Posts

Posted - 08/02/2006 :  07:21:13  Show Profile  Reply with Quote
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

Sweden
30265 Posts

Posted - 08/02/2006 :  07:27:25  Show Profile  Visit SwePeso's Homepage  Reply with Quote
update SecurityModule
set ModKey = ModKey + 1
where modkey >= 3


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000