View previous topic :: View next topic
|
Author |
Message |
gauravgupta2808 Warnings : 1 New User
Joined: 31 May 2007 Posts: 31 Location: Chennai, India
|
|
|
|
Hi,
I have a data like this in
Code: |
Sort Account FName SName
1001 10001 F1 S1
1001 10002 F2 S2
1001 10001 F3 S3
|
I need to select the concatenated FName SName (separated by &) for all similar Sort Account
Like if input is 1001 10001, then output should be:
Code: |
1001 10001 F1 S1 & F3 S3
|
Can you please suggest me some query |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
What should happen when there 800 rows of the same sort/account values?
What should happen when there are multiples of the same Fname/Sname? Should duplicates be discarded? |
|
Back to top |
|
|
gauravgupta2808 Warnings : 1 New User
Joined: 31 May 2007 Posts: 31 Location: Chennai, India
|
|
|
|
Hi,
In an ideal scenario, there will not be mor ethan 5-6 Sortcode & acoount
There will be no similar FName & SName,,, if they do occur, duplicates are not discarded |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
Ideal scenarios don't happen.
What about an account held by Albert Smith and his son Albert Smith Jr and his grandson Albert Smith III. Maybe they were got busy at a young age and there is a great grandson named Albert Smith IV? |
|
Back to top |
|
|
gauravgupta2808 Warnings : 1 New User
Joined: 31 May 2007 Posts: 31 Location: Chennai, India
|
|
|
|
In this case, if they hold sortcode 10001 & Account 20001 then it should display
10001 20001 Albert Smith & Albert Smith Jr & Albert Smith III
If great grandson is also there, then:
10001 20001 Albert Smith & Albert Smith Jr & Albert Smith III & Albert Smith IV
PS: The order in which the names are displayed doesnot matter. |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
You can't do that on a select then. Even if you could, if someone had to come back and do maintenance on it, they would want to strangle the person who wrote it. You should do post processing through COBOL or something.
Setup your query with an order by Sort, Account then loop through it using STRING. |
|
Back to top |
|
|
zero
New User
Joined: 01 Dec 2007 Posts: 21 Location: Hyderabad
|
|
|
|
Hi,
if there are only two records for any SORT and ACCOUNT combination, we can use the following query :
SELECT A.SORT, A.ACCOUNT, CONCAT(CONCAT(CONCAT(A.FNAME,A.LASTNAME), '&'),CONCAT(B.FNAME,B.LASTNAME))
FROM SILLY2 A, SILLY2 B
WHERE A.SORT = B.SORT
AND A.ACCOUNT = B.ACCOUNT
AND A.FNAME <> B.FNAME
ORDER BY A.FNAME, A.LASTNAME
Fetch first 1 row only; |
|
Back to top |
|
|
|