Click here to Skip to main content
15,443,430 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
SQL Server Export Query Results to Excel with Column Names but not data.


What I have tried:

C#
SQL Server Export Query Results to Excel with Column Names but not data.
Posted
Updated 21-Oct-16 10:50am

1 solution

The question that comes in to mind first is "Why would that be needed any way?"
Well, there is a way for everything, check following approaches if these help-
---Export the result with header and remove the data rows
---Use a condition in WHERE clause which will be evaluated to false always so as to make sure you will not get any data rows and just the headers.

Something like -
SQL
SELECT * FROM MyTable WHERE 1<>1


Hope, it helps :)
 
Share this answer
 
Comments
verma.vivek 22-Oct-16 5:39am     CRLF
1. I should not need data, Only Columns Name. 2. and The sheet name of Excel is same as Table Name. 3. and on the same Excel file use no. of sheets as table name & their attributes(column name)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900