原创  关于两个标识字段并存的处理办法。 收藏

--关于两个标识字段并存的处理办法。
SELECT identity(int,1,1)AS number,cast(ID as int)ID,* into #tem from Company
order by hits desc,lastlogintime DESC   
select*from #tem   
DROP table #tem
现在想在检索到的记录行在添加上一个流水号(  1  2  3  4  5  6  7 ) 
照别人做的语句改了几次,就是编译不过, 
报错信息: 
消息 8108,级别 16,状态 1,第 1 行 
无法使用 SELECT INTO 语句向表 '#tem' 中添加标识列,该表中已有继承了标识属性的列 'ID'。 
请sql高手们帮助,谢谢!  
==============================================================
--你的表里面已经有一个标识字段ID了,所以生成临时表的时候不能再生成一个标识字段了。
--要这样。
SELECT identity(int,1,1)AS number,cast(ID as int) ID,其他字段列表不包括那个ID into #tem 
from Companyorder by hits desc,lastlogintime DESC   
select*from #tem   
DROP table #tem

发表于 @ 2009年06月27日 13:38:00 | 评论( loading... ) | 编辑| 举报| 收藏

旧一篇:浅析触发器 | 新一篇:存储过程中如何根据参数是否为空执行不同的select??

  • 发表评论
  • 评论内容:
  •  
Copyright © sdhdy
Powered by CSDN Blog