[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Select Comma Separated List

Posted on 2007-10-21
10
Medium Priority
?
1,898 Views
Last Modified: 2008-01-15
I want to select comma separated enames as single value for salary = 5000 from employee table. Please give me a single query to get this.
0
Comment
Question by:k_murli_krishna
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 20118337
can you put an example ot what you need ?
if i understand you correctly, if your table contains

emp1, 5000
emp2, 5000
emp3, 6000
emp4, 1000
emp5, 5000

you want a select statement that will return - emp1,emp2,emp5 ?
0
 
LVL 27

Expert Comment

by:tliotta
ID: 20120793
I _think_ the question is looking for:

  select name1 CONCAT ', ' CONCAT name2 CONCAT ', ' CONCAT name3 as "Name" from myfile

Columns may need to be trimmed or other manipulation.

Tom
0
 
LVL 27

Expert Comment

by:tliotta
ID: 20120799
More precisely would be:

   select name1 CONCAT ', ' CONCAT name2 CONCAT ', ' CONCAT name3 as "Name" from myfile where salary = 5000

Tom
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 17

Author Comment

by:k_murli_krishna
ID: 20120911
momi, what you understood is spot on. Please provide the query.
tliotta: name1, name2 etc are not separate columns but the way momi has laid the data out i.e. ename is sinlge name column.
0
 
LVL 27

Expert Comment

by:tliotta
ID: 20121337
If that's the case, then I'm not sure an answer would be useful. It sounds as if it's an incorrect problem. The best answer might be that you shouldn't put data like that into DB2 in the first place.

Perhaps the situation is that data is being received as a .CSV and it isn't being put into DB2 correctly. A proper answer should indicate how to eliminate the improperly formatted data so that such a query is never needed.

I'm concerned that the expectation is that a DB2 query can be used against any .CSV file or that a .CSV format is a reasonable format for DB2 rows. The potential result might be a table that is a very poor performer.

Tom
0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 20121384
you can get the output you wish using recursive sql
i'm trying to work on it, but i'm a bit rusty with recursive sql so it might take me some time
0
 

Expert Comment

by:vermakrish
ID: 20122930
hi,
  Try ..
     SELECT ENAME ||','  FROM EMPLOYEE WHERE salary = 5000 ;

this would give u the following o/p
  ename1  ,
  ename2  ,
   ename3  .......


Hopefully it will solve ur problem.
0
 
LVL 17

Author Comment

by:k_murli_krishna
ID: 20601582
momi, I tried with recursive SQL i.e. using WITH clause but this is used for reusability rather than a true recursion used in calculating factorial of a number. Please do provide me an example of recursive SQL that you are suggesting.
0
 
LVL 37

Accepted Solution

by:
momi_sabag earned 200 total points
ID: 20602395
hi
try to look here
  http://www.experts-exchange.com/Database/DB2/Q_22642179.html
it has an example
0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 20602401
if you can't figure it out, i'll help you of course
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question