select * into #one from (
select * 
from (select [f_uesr],[商品编码]='a',[数量]=[a] ,[f_bhrq],[f_ip] from cs union all 
select [f_uesr],[商品编码]='b',[数量]=[b] ,[f_bhrq],[f_ip] from cs union all 
select [f_uesr],[商品编码]='c',[数量]=[c] ,[f_bhrq],[f_ip] from cs union all 
select [f_uesr],[商品编码]='d',[数量]=[d] ,[f_bhrq],[f_ip] from cs)t
order by [商品编码]服务器: 消息 1033,级别 15,状态 1,行 7
除非同时指定了 TOP,否则 ORDER BY 子句在视图、内嵌函数、派生表和子查询中无效。执行上面的语句提示错误。但是如果我不要select * into #one from ,单单执行后面的是有数据出来的。

解决方案 »

  1.   

    还是一样
    order by [商品编码] asc或desc服务器: 消息 1033,级别 15,状态 1,行 7 
    除非同时指定了 TOP,否则 ORDER BY 子句在视图、内嵌函数、派生表和子查询中无效。 
      

  2.   

    select * into #one 
    select [f_uesr],[商品编码]='a',[数量]=[a] ,[f_bhrq],[f_ip] from cs union all 
    select [f_uesr],[商品编码]='b',[数量]=[b] ,[f_bhrq],[f_ip] from cs union all 
    select [f_uesr],[商品编码]='c',[数量]=[c] ,[f_bhrq],[f_ip] from cs union all 
    select [f_uesr],[商品编码]='d',[数量]=[d] ,[f_bhrq],[f_ip] from cs
    order by [商品编码] 
      

  3.   


    select * into #one from ( 
    select * from 
    (
    select [f_uesr],[商品编码]='a',[数量]=[a] ,[f_bhrq],[f_ip] from cs union all 
    select [f_uesr],[商品编码]='b',[数量]=[b] ,[f_bhrq],[f_ip] from cs union all 
    select [f_uesr],[商品编码]='c',[数量]=[c] ,[f_bhrq],[f_ip] from cs union all 
    select [f_uesr],[商品编码]='d',[数量]=[d] ,[f_bhrq],[f_ip] from cs)t )tt
    order by [商品编码]