这样写的identity为什么会有语法错误呢?

xuehf 2007-03-03 10:58:25
declare @f1 as int

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

系统提示语法错误,如何来写?
...全文
216 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
no_mIss 2007-03-03
  • 打赏
  • 举报
回复
也可以如下:
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)
xuehf 2007-03-03
  • 打赏
  • 举报
回复
明白了,谢谢
mengmou 2007-03-03
  • 打赏
  • 举报
回复
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

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧