0

I am currently using a sql query in excel so the users can get the results by refreshing the worksheet.

The results are getting displayed but the columns are in different order than what they should be according to my query

In excel in the Data Tab, I have chosen from other sources and had chosen from sql server then i connect to my database. I get an option to input my sql command (query) and it runs perfectly fine. But the columns are in different order than especified in my query.

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

RESULTS in Microsoft sql server Management studio:

NAME, DOB, ID, ADDRESS, PROGRAM_NAME 

Results in excel

PROGRAM_NAME, ID, ADDRESS, DOB,NAME

Excel

Results in sql server management studion

I HAVE TRIED REWRITING THE QUERY BUT YET I GET THE SAME RESULT. CAN THIS BE WORKED AROUND?

1

I am not positive this is an answer, but is it possible the External Data Properties are impacting your field positions?

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.