为什么这个sql语句有错
select ID_Num from (SELECT IDENTITY(int, 1,1) AS ID_Num ,test INTO #
FROM test order by age desc)
------解决方案--------------------SELECT IDENTITY(int, 1,1) AS ID_Num ,id INTO # FROM test
-----------------------------------
这是个创建表的语句,而不是查询语句,不会返回查询结果,不能作为子查询.
楼主应该将语句拆开:
SELECT IDENTITY(int, 1,1) AS ID_Num ,id INTO # FROM test order by age desc
select ID_Num from # where id =@id
------解决方案--------------------select ID_Num from (SELECT IDENTITY(int, 1,1) AS ID_Num ,test INTO #
FROM test order by age desc)
生成表不能放在查询里:
SELECT IDENTITY(int, 1,1) AS ID_Num ,test INTO #
FROM test order by age desc
--再查询
select ID_Num from #