在Excel中使用sql查询以正确的顺序显示列


0

我目前在excel中使用sql查询,因此用户可以通过刷新工作表来获得结果。

结果将显示,但根据我的查询,列的顺序与它们应该的顺序不同

在数据选项卡中的excel中,我从其他来源中选择并从sql server中选择然后我连接到我的数据库。我得到一个输入我的sql命令(查询)的选项,它运行得很好。但是列的顺序与查询中指定的顺序不同。

select p.first_name + ' ' + p.last_name as Name, CONVERT(CHAR(10), dob, 101) AS DOB, st.id_no AS ID, addr.address, e.program_name as Program_Name
--case when end_date is null then 'Y' else 'N' end as 'Enrolled?' 

from programenrollment e With (NoLock)  


join people p on e.people = p.people
left outer join service_track st WITH(NOLOCK) ON p.people = st.people
left outer join person_address addr on st.people = addr.people



 where e.is_deleted = 0

and((end_date is null) or (end_date >= GETDATE()))
and e.people is not null
and program_name in (
  'Physical Education',
  'Music'

) 


order by name, e.program_name--, st.id_no

结果在Microsoft sql server Management studio中:

NAME, DOB, ID, ADDRESS, PROGRAM_NAME 

结果excel

PROGRAM_NAME, ID, ADDRESS, DOB,NAME

高强

结果在sql server management studion中

我已经尝试过重写但我得到了相同的结果。这可以在周围工作吗?

Answers:


1

我不肯定这是一个答案,但外部数据属性是否可能影响您的现场位置?

在此输入图像描述

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.