我一般在进行数据库访问时都是调用存储过程来进行数据操作的,下面是一个最基本的存储过程书写方式。

 1 alter procedure [dbo].[lsp_EditURL] as
 2     declare @typo varchar(255)
 3     declare @id int
 4     declare w_cursor CURSOR FOR
 5     select [id],[content] from dbo.doc where parent>0
 6     open w_cursor
 7     fetch NEXT fron w_cursor into @id,@typo
 8     while @@FETCH_STATUS = 0
 9     begin
10         if CharIndex('smileyes/u/',@typo)>0
11         begin
12             update doc set [content]=replace(@typo,'smileyes/u/','smileyes/userphoto/') where id=@id
13         end
14     fetch NEXT from w_cursor into @id,@typo
15     end
16     close w_cursor
17 deallocate w_cursor

 

 调用的时候只需要  exec dbo.lsp_EditURL

posted on 2012-07-27 15:05  振宇爸爸  阅读(180)  评论(0编辑  收藏  举报