【发布时间】:2015-04-19 06:07:33
【问题描述】:
我的确切要求是:我有一个未按顺序排列的Employee 表,所以我想首先按 NM 对其进行排序,然后在表的开头插入一个新行。
Insert into #temptable(ID, name, place,Address)
Select
ID, name, place, Address
from
Employee
order by
NM
Select
0 as ID,
'Select Employee' as NM,
'No place' as place,
'No address' as Address
Union All
Select
w.ID, w.NM, w.Place, w.Address
from
#temptable w
我希望联合查询的第二部分由 NM 排序。 上述方法没有按顺序给我结果
建议我使用其他方法,因为这在 SQL Server 2012 中不起作用
【问题讨论】:
-
Define “不工作” - 你是否收到错误 - 如果是,what 错误?你根本没有得到任何结果吗?你得到结果,但没有订购??
-
选择 0 作为 ID,'Select Employee' 作为 NM,'No place' 作为地方,'No address' 作为地址 Union All SELECT t.* FROM (Select w.ID, w.NM, w.Place, w.Address FROM #temptable w ORDER BY w.NM) t 我尝试了这个查询,它抛出“The Order by Clause 在视图、内联函数、查询中是有效的。请帮助我
标签: sql-server-2012