【发布时间】:2019-12-18 08:36:03
【问题描述】:
我创建了一个查询,通过该查询从表的列中获取不为空的值:
Select * from(
SELECT OEID, Chest_Pain as Head, Chest_PainComment as Detail
FROM tblComplaints
union
SELECT OEID, SOB as Head, SOBComment as Detail
FROM tblComplaints
union
SELECT OEID, PND as Head, Cyanosis as Detail FROM tblComplaints
union
SELECT OEID, Odema_Feet as Head, Vertigo + as Detail From tblComplaints
union
SELECT OEID, DM as Head, DMComment as Detail
FROM tblComplaints
union
SELECT OEID, RS as Head, RSComment as Detail
FROM tblComplaints
) as t
where (Head is not null and ltrim(rtrim(Head)) <> '')
and OEID = 6012
数据很好,但问题是这个查询会自动在输出结果中进行 A 到 Z 排序。我需要做的是按照我输入每一行的方式得到结果。
例如:目前我得到这个查询的输出如下:
Head Detail
Chest_Pain Chest_PainComment
DM DmComment
Odema_Feet Vertigo
PND Cyanosis
RS RSComment
我希望它是这样的:
Head Detail
Chest_Pain Chest_PainComment
RS RSComment
PND Cyanosis
DM DMComment
底线不应该是 A 到 Z 排序,这发生在我的查询中。我不知道为什么在查询中会发生这种 A 到 Z 排序,而我没有在任何地方对其进行排序。
我将不胜感激。
【问题讨论】:
标签: sql sql-server visual-studio sorting union