首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

为什么这个sql语句有错解决办法

2012-03-03 
为什么这个sql语句有错selectID_Numfrom(SELECTIDENTITY(int,1,1)ASID_Num,testINTO#FROMtestorderbyagede

为什么这个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 #

热点排行