求一Sql - MS-SQL Server / 应用实例
我的数据库现存在如下类型字段和数据
A B
712 010101
212 010101
321 010101
434 010101
523 010101
656 010101
怎样将B字段数据实现如下
712 010101
212 010102
321 010103
434 010104
523 010105
656 010106
SQL code:
if not object_id('tb') is null
drop table tb
Go
Create table tb([A] int,[B] varchar(10))
Insert tb
select 712,'010101' union all
select 212,'010101' union all
select 321,'010101' union all
select 434,'010101' union all
select 523,'010101' union all
select 656,'010101'
Go
declare @i int
set @i=0
update tb set b='0101'+right(100+@i,2),@I=@i+1
select * from tb
/*
A B
----------- ----------
712 010101
212 010102
321 010103
434 010104
523 010105
656 010106
(6 個資料列受到影響)
*/
SQL code:
update
tb
set
b=b.b
from
tb a,
(select a,left(b,5)+ltrim(row_number()over(order by getdate())) as b from tb)b
where
a.a=b.a
...
SQL code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
相关问答:
我一个项目,有个插入操作,具体是这样的:
我有进货信息表。在出货时选择相应的进货信息,输入数量,选择部门后,点保存按钮,由于网络延时,点一下没有反映,于是用户就又点一下,导致一次插入了两条记录:
例:
......
今天做了一个存储过程 环境是SQL2000数据库
大致如下
建立临时表
定义员工游标
循环员工(属于1个公司)
......
从数据库中查询一张表的数据
select 部门,姓名 from tb
如何才能生成下面的xml格式
XML code:
<folder state="unchecked" label="全部">
<folder state="unchecked&qu ......
字段1,字段2.....字段N,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
想要的结果是:
1,Na ......
请教高手:
以下是数据库中的三条记录,英文为字段名称
id planname TaskBeginTime Status
329 2010年03 ......