GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  SQL
Go To First  |  Previous Question  |  Next Question 
 SQL  |  Question 151 of 171    Print  
How to get the row values as comma separated by a query

  
Total Answers and Comments: 4 Last Update: May 16, 2008     Asked by: Santosh Bhor 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: krishnaindia2007
 
Set heading off
Sset feedback off 
SPOOL TEST.LST
SELECT ENAME ||','||JOB||','||SAL FROM EMP;
SPOOL OFF;
SET HEADING ON
SET FEEDBACK ON

Above answer was rated as good by the following members:
spohilko
November 28, 2007 10:50:44   #1  
gurudevi Member Since: November 2007   Contribution: 4    

RE: How to get the row values as comma separated by a query
U need to use a cursor and display them using concat operator with comma
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
December 18, 2007 12:25:10   #2  
Waseem Mehmood Member Since: November 2007   Contribution: 11    

RE: How to get the row values as comma separated by a query
SELECT ENAME ||''' '||HIREDATE||''' '||SAL

FROM EMP

Like this query you can get the required result.


 
Is this answer useful? Yes | No
May 16, 2008 04:35:05   #3  
krishnaindia2007 Member Since: September 2007   Contribution: 854    

RE: How to get the row values as comma separated by a query
Set heading off
Sset feedback off
SPOOL TEST.LST
SELECT ENAME ||' '||JOB||' '||SAL FROM EMP;
SPOOL OFF;
SET HEADING ON
SET FEEDBACK ON

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 1Overall Rating: -N/A-    
May 16, 2008 10:09:25   #4  
vinod.km Member Since: May 2008   Contribution: 2    

RE: How to get the row values as comma separated by a query
What I understood from your question is that you want to comma seperate the values of a particular column for its different rows. If this the question then query will be

DECLARE @SQL AS VARCHAR(500)

SELECT @SQL ISNULL(@SQL ' ')+' ' + ColumnName FROM TableName

SELECT @SQL



 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 3Overall Rating: -3    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape