日期:2014-05-19  浏览次数:20413 次

这样写的identity为什么会有语法错误呢?
declare   @f1   as   int

set   @f1=20     /*   @f1的值是从另一个表中取得的,我这里写了一个固定值   */
select   identity(int,@f1,1)
into   #temp1
  from   tblInfo  

系统提示语法错误,如何来写?

------解决方案--------------------
declare @f1 as int

set @f1=20 /* @f1的值是从另一个表中取得的,我这里写了一个固定值 */

select identity(int,0,1) as id--identity 的参数只能是常量
into #temp1
from tblInfo

update #temp1
set id = id + @f1

------解决方案--------------------
也可以如下:
declare @f1 as int
set @f1=20 /* @f1的值是从另一个表中取得的,我这里写了一个固定值 */
declare @sql as varchar(8000)
set @sql = 'select identity(int, '+ str(@f1) + ',1) as id into #temp1 from t_test select * from #temp1 '
exec(@sql)