Home » SQL & PL/SQL » SQL & PL/SQL » SQL query for table cloumn name (SQL query for table cloumn name)
SQL query for table cloumn name [message #282265] Wed, 21 November 2007 05:58 Go to next message
sonalshastry
Messages: 52
Registered: September 2007
Member
Hi all

I wants some idea/suggetion for a SQL query .
I wants to save a output of a query with the (table)cloumn name not with alias in CSV file

just like the option 'Copy with Header' available in PLSQL

please reply soon

regards
sonal

Re: SQL query for table cloumn name [message #282271 is a reply to message #282265] Wed, 21 November 2007 06:24 Go to previous messageGo to next message
Michel Cadot
Messages: 64151
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Not directly possible in SQL.
You have to build the headers:
SQL> set head off
SQL> select 'EMPNO','ENAME','HIREDATE' from dual
  2  union all
  3  select to_char(empno), ename, to_char(hiredate) from emp;
EMPNO                                    ENAME      HIREDATE
7369                                     SMITH      17/12/1980 00:00:00
7499                                     ALLEN      20/02/1981 00:00:00
7521                                     WARD       22/02/1981 00:00:00
7566                                     JONES      02/04/1981 00:00:00
7654                                     MARTIN     28/09/1981 00:00:00
7698                                     BLAKE      01/05/1981 00:00:00
7782                                     CLARK      09/06/1981 00:00:00
7788                                     SCOTT      19/04/1987 00:00:00
7839                                     KING       17/11/1981 00:00:00
7844                                     TURNER     08/09/1981 00:00:00
7876                                     ADAMS      23/05/1987 00:00:00
7900                                     JAMES      03/12/1981 00:00:00
7902                                     FORD       03/12/1981 00:00:00
7934                                     MILLER     23/01/1982 00:00:00

15 rows selected.

Regards
Michel
Re: SQL query for table cloumn name [message #282283 is a reply to message #282271] Wed, 21 November 2007 06:43 Go to previous messageGo to next message
sonalshastry
Messages: 52
Registered: September 2007
Member
HI
I wanted this query in MSSQL so I worte it like this
set head off
select 'ORD_ORDER_NO','ORD_SERIAL_NO','ORD_EXCH_ID' from matrix_ows_order_log_new
    union all
select CONVERT(VARCHAR(20),ORD_ORDER_NO),CONVERT(VARCHAR (20),ORD_SERIAL_NO),ORD_EXCH_ID from matrix_ows_order_log_new


& got error

Server: Msg 195, Level 15, State 5, Line 1
'head' is not a recognized option.


please suggest what will bwe the recognized option

regards
sonal
Re: SQL query for table cloumn name [message #282286 is a reply to message #282283] Wed, 21 November 2007 06:45 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
You're aware that Oracle and MSSQL are not the same?
And that this is an Oracle forum?

Why do you think that Oracle SQL*Plus output configuration commands like 'SET HEAD OFF' would work in MSSQL?

I despair, I really do.
Re: SQL query for table cloumn name [message #282292 is a reply to message #282283] Wed, 21 November 2007 06:53 Go to previous messageGo to next message
Michel Cadot
Messages: 64151
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
In addition to JRowbottom, this statement (set head off) is not part of the solution, it is just there to show the header (the column names) is not generated by the tool.

Just try the statement.

Regards
Michel
Re: SQL query for table cloumn name [message #282297 is a reply to message #282286] Wed, 21 November 2007 06:59 Go to previous messageGo to next message
sonalshastry
Messages: 52
Registered: September 2007
Member

i am sorry sir

actually a i am new for MS SQL & i now that MSSQL & PLSQL are diffrent but i want the same thing that i do with PLSQL.

If someone can help me in MSSQL so please help me.

sonal
Re: SQL query for table cloumn name [message #282299 is a reply to message #282297] Wed, 21 November 2007 07:00 Go to previous messageGo to next message
Michel Cadot
Messages: 64151
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Follow what I said.

Regards
Michel
Re: SQL query for table cloumn name [message #282300 is a reply to message #282297] Wed, 21 November 2007 07:01 Go to previous message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
Not Oracle Related. Have a look at the Forum Guidelines for a SQL Server forum (MSDN).

http://www.orafaq.com/forum/fa/448/0/

Closed.

MHE
Previous Topic: How can I store sql query result in different tabs of excel
Next Topic: Which is better, returning a ref cursor or using out mode parameter in a function?
Goto Forum:
  


Current Time: Fri Dec 09 22:52:11 CST 2016

Total time taken to generate the page: 0.08652 seconds