I am trying to extract the values from an mdf database to excel, but i can't display the header texts(title fields). I can only view the values. In order to make this work i need a query like this below, but it seems that select with cte gives me an error.

enter image description here


When you paste code as an image, it's difficult the take that code and rewrite it to show you the correct way to do it. You should always paste your code as text when asking a question.

You need to put the WITH CTE at the beginning of the sql =, such that

sql = ";with cte as (select *, row_number() over()... FROM [TABLE])
SELECT (Your Headers)    
SELECT (Specific columns) from cte
  • Thank you! It worked with the word distinct inside my header parenthesis! – Paulos Xampos Jan 2 '19 at 23:20

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.