SELECT identity(int,0,1) N_ID,ID INTO #TB FROM aa包错
无法使用 SELECT INTO 语句将标识列添加到表 '#TB',该表的列 'ID' 已继承了标识属性要怎么才能在临时表里面插入已经是标识属性的列呢?
无法使用 SELECT INTO 语句将标识列添加到表 '#TB',该表的列 'ID' 已继承了标识属性要怎么才能在临时表里面插入已经是标识属性的列呢?
调试欢乐多
n_id int identity(0,1),
id int
)insert into #t (id)
SELECT ID FROM aa
你已经有标志列了呀
create table #temp(id int identity,b int)set identity_insert #temp oninsert #temp(id,b)
select 1,2select * from #tempset identity_insert #temp offdrop table #temp
SET @sql='INSERT INTO '+@IndexTable(id)+' SELECT '+@ID+' FROM '+@Table+@where+@Sort消息 137,级别 15,状态 2,第 2 行
必须声明标量变量 "@IndexTable"。这个要怎么解决呢??
SET @sql='
DECLARE @IndexTable table(n_id int identity(1,1),id int)
INSERT INTO @IndexTable(id) SELECT '+@ID+' FROM '+@Table+@where+@Sort +
'select * from @IndexTable'
注意:此方法中表变量@IndexTable的定义和使用必须都写在一个SQL字符串中,也就是说放到一个语句块中.当使用EXEC(@sql)后,@IndexTable表变量就被自动销毁,无法再被访问了.如果希望在EXEC(@sql)之后能继续被访问,请使用下面的方法,创建局部临时表(#).----方法二:
CREATE TABLE #IndexTable table(n_id int identity(1,1),id int)
SET @sql='INSERT INTO #IndexTable(id) SELECT '+@ID+' FROM '+@Table+@where+@Sort
EXEC(@sql)
select * from #IndexTable /*可以在EXEC之后继续访问*/