| Author |
Topic |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-05-09 : 06:10:02
|
| Is there a query that will retrun column names as seperate columns?I have a table test having the columns id, name and specI can write a querySelect name from syscolumns order by colorderbut the output is idnamespecbut my desired output woulld beCol1 Col2 Col3id name specMadhivananFailing to plan is Planning to fail |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-05-09 : 10:26:11
|
| Why?Do you want separate columns or a delimted srring?Brett8-) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-05-10 : 00:31:33
|
| Brett, I want seperate columns not delimited stringMadhivananFailing to plan is Planning to fail |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2005-05-10 : 08:57:56
|
| Why do you want this? what are doing with this data? Your presentation layer can easily determine the columns from a recordset and display them any way you want, if your goal is just to list/present these columns. A brief paragraph about what tools you are using and what your goal is might be really helpful here, it sounds like you are making things more complicated then they need to be.- Jeff |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-05-10 : 09:04:53
|
| Jeff, Actually I want to export the data to Excel fileFrom QA, I run query and results are displaying in the Grid. When I copy the contents of Grid and paste in Excel, Column names are not copied. Thats why I wanted to do thisMadhivananFailing to plan is Planning to fail |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2005-05-10 : 09:11:31
|
| see how you are overcomplicating things to accomodate a simple cut and paste?here's 3 ways to do this quite easily:1) don't use the grid in query analyzer, use the text format for you results. Run the SQL, copy all of the results, paste into Excel and when they are all still highlighted use Data->Text to Columns and choose Fixed width. This turns your large 1 column text result into multiple columns quite well, with headers.2) Another idea is to use MS Access as a middle-man between SQL and Excel -- it works great and query results in Access paste into Excel quite nicely. Create view of your SQL in SQL Server and link to it in Access. Or use a pass-through query in Access that links directly into SQL Server for ad-hoc SQL execution. The results are in a nice grid that is easily pasted into Excel.3) if you do this often, you can create a view and link directly into SQL Server from Excel, look at Data-->Get External Data. Or you can export from SQL Server using DTS into an Excel file.Does this help?- Jeff |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-05-10 : 09:37:47
|
| yes, this really helps. Thanks JeffMadhivananFailing to plan is Planning to fail |
 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-05-10 : 09:55:45
|
| If You use these options: (QA->Options->Results)"Results To Text""Tab Delimited"Then the result will copy straight in to Excel, with column headers an' all.rockmoose |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-05-10 : 10:01:02
|
| rockmoose, Yours also good ideaMadhivananFailing to plan is Planning to fail |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-05-10 : 10:18:59
|
>> Then there's always the hard way...just cut and paste the code and you're good to goI knew, there had to be a harder way. rockmoose |
 |
|
|
|