现有表icmo,表内有若干列,其中有fnote列为空,属性为string。fdate为数据建立时间希望设置icmo表内fdate在2010-01-01到2010-06-30的时间段的fnote值为递增的数字,格式为NO10*****之前问过递增的问题,虽然解答的很好,但是和我的情况有所区别,感谢高手的解答
解决方案 »
- 如何通过存储过程把含有关键字“苹果”的文章的类别字段标志为1,含有“镜子”的文章的类别字段标志为为2?
- 语法错误,帮我看一下.
- 求一条SQL语句
- 【急】现有一张表,想查询创建它或负责往该表插入数据的存储过程
- 高分求解数据库导出Excel的问题!至少给50分!绝不食言
- 表有几十个字段,但是除了其中一个,都需要选择,可以用select * 吗?
- sql2000 里 binary 转换为 char
- 十分难的问题,有高分,解决后立刻奉送
- 请教SQL语言编程问题!!
- SqlServer2008 打开SqlServer2000备份的.BAK 文件
- 查找表里相同数据怎么做(在线等)
- 你知道这个SQL2000的这个问题吗
希望设置icmo表内fdate在2010-01-01到2010-06-30的时间段 又是何意呢?
declare @t table([id] int,[B] NVARCHAR(200))
insert @t
select 1,null union all
select 2,null union all
select 3,null union all
select 4,null union all
select 5,null union all
select 6,null union all
select 7,null union all
select 8,null union all
select 9,null
SELECT CASE b.number WHEN 1 THEN 'NO'+RIGHT(1000000+ISNULL(RIGHT((b.number),6),0),6)
else RIGHT(1000000+ISNULL(RIGHT((b.number),6),0),6) end
FROM @t a,(select distinct number from master..spt_values where number > 0 )b
where a.id = b.number
declare @t table([id] int,[B] NVARCHAR(200))
insert @t
select 1,null union all
select 2,null union all
select 3,null union all
select 4,null union all
select 5,null union all
select 6,null union all
select 7,null union all
select 8,null union all
select 9,null
--SELECT CASE b.number WHEN 1 THEN 'NO'+RIGHT(1000000+ISNULL(RIGHT((b.number),6),0),6)
--else RIGHT(1000000+ISNULL(RIGHT((b.number),6),0),6) end
--FROM @t a,(select distinct number from master..spt_values where number > 0 )b
--where a.id = b.number UPDATE a
SET B = M.PX
from @t a ,(SELECT a.id,CASE b.number WHEN 1 THEN 'NO'+RIGHT(1000000+ISNULL(RIGHT((b.number),6),0),6)
else RIGHT(1000000+ISNULL(RIGHT((b.number),6),0),6) end as PX
FROM @t a,(select distinct number from master..spt_values where number > 0 )b
where a.id = b.number ) M
where a.id = M.id and a.fdate between '2010-01-01' and '2010-06-30'根据你的表再添加时间判断条件吧
declare @t table([a] int,fnote varchar(10))
insert @t
select 1,null union all
select 2,null union all
select 3,null union all
select 4,null union all
select 5,null union all
select 6,null union all
select 7,null union all
select 8,null union all
select 9,null
declare @s int,@v varchar(10)set @s=0update @t set @s=@s+1,@v='no10'+right('000000'+ltrim(@s ),6) ,fnote=@v
--where fdate between '2010-01-01' and '2010-06-30' ---把这个条件启用就可以了
select * from @t
a fnote
----------- ----------
1 no10000001
2 no10000002
3 no10000003
4 no10000004
5 no10000005
6 no10000006
7 no10000007
8 no10000008
9 no10000009(9 行受影响)
update t
set t.fnote='NO'+ltrim(10000000+(select count(1)+1 from icmo where fdate<t.fdate))
from icmo t
其他参考 update中变量的赋值用法 实现分组更新序号
http://blog.csdn.net/xys_777/archive/2010/07/21/5753206.aspx