declare my_cursor cursor
for select id from testtable
open my_cursor
fetch next from my_cursor
/*帮我实现下面这个update*/
/* update testtable set id=(case when (substring(id,1,1)='B') then '1'
else '2' end)+(substring(id,2,1))+(substring(id,4,3))
update testtable set id='6'+id */close my_cursor
deallocate my_cursorB10011 结果 611011
B20012 612012
C30013 623013
C40014 624014
for select id from testtable
open my_cursor
fetch next from my_cursor
/*帮我实现下面这个update*/
/* update testtable set id=(case when (substring(id,1,1)='B') then '1'
else '2' end)+(substring(id,2,1))+(substring(id,4,3))
update testtable set id='6'+id */close my_cursor
deallocate my_cursorB10011 结果 611011
B20012 612012
C30013 623013
C40014 624014
解决方案 »
- 还是非常菜的问题,需要大家再帮一个忙,小弟在此先谢过了!
- 简单问题,在线等:怎么做字符串相加,例如 "0001"+1="0002"
- sqlserver有没有工具来查看它自己的事务志?Log Explore等第三方软件不算
- sqlserver2008维护计划出错
- 函数问题
- 如果让不重复的字段显示,sql语句如何写,非常紧急,请教各位,多谢了!
- ~~~~~~~~~~~~这样如何实现~~~~~~~~~~~~~~~~~~~~~~~~
- 求一张表拆分成几张表的sql语句 在线等
- 在mssql可以把一个表a的内容复到另一个表b的数据结束处的位置的吧 只要这两个表的结构一样就可以的吧 命令怎样的
- 有没有知道吗?有水平的人到哪儿去了?????????
- char能存储符号吗?
- SQL 2005 导入数据时 停止、出错
insert testtable select 'B10011'
insert testtable select 'B20012'
insert testtable select 'C30013'
insert testtable select 'C40014'go
--这样的情况不用游标,用语句效率高:
update testtable
set ID='6'+case when substring(ID,1,1)='B' then '1' else '2' end+substring(ID,2,1)+substring(ID,4,3)goID
----------
611011
612012
623013
624014(所影响的行数为 4 行)
select ID from testtable order by ID
declare @ID nvarchar(10),@ID2 nvarchar(10)
open test
fetch next from test into @ID
while @@fetch_status=0
begin
select @ID2='6'+case when substring(@ID,1,1)='B' then '1' else '2' end+substring(@ID,2,1)+substring(@ID,4,3) update testtable
set ID=@ID2
where ID=@ID fetch next from test into @ID
end
close test
deallocate test
goselect * from testtable