Click here to Skip to main content
15,792,771 members
Home / Discussions / Database
   

Database

 
QuestionRe: SQL server 12: Displaying column cell values in single cell Pin
Eddy Vluggen17-Feb-15 5:38
professionalEddy Vluggen17-Feb-15 5:38 
AnswerRe: SQL server 12: Displaying column cell values in single cell Pin
Richard Deeming17-Feb-15 5:01
mveRichard Deeming17-Feb-15 5:01 
GeneralRe: SQL server 12: Displaying column cell values in single cell Pin
Swap917-Feb-15 6:16
Swap917-Feb-15 6:16 
GeneralRe: SQL server 12: Displaying column cell values in single cell Pin
Richard Deeming17-Feb-15 6:22
mveRichard Deeming17-Feb-15 6:22 
GeneralRe: SQL server 12: Displaying column cell values in single cell Pin
Swap917-Feb-15 6:36
Swap917-Feb-15 6:36 
GeneralRe: SQL server 12: Displaying column cell values in single cell Pin
Richard Deeming17-Feb-15 6:44
mveRichard Deeming17-Feb-15 6:44 
GeneralRe: SQL server 12: Displaying column cell values in single cell Pin
Swap917-Feb-15 6:51
Swap917-Feb-15 6:51 
GeneralRe: SQL server 12: Displaying column cell values in single cell Pin
Richard Deeming17-Feb-15 6:59
mveRichard Deeming17-Feb-15 6:59 
I've just tried the code here on your sample data, and I get the expected output.
SQL
DECLARE @T TABLE
(
	ID int NOT NULL,
	Surname varchar(10) NOT NULL,
	Forename varchar(10) NOT NULL
);

INSERT INTO @T (ID, Surname, Forename)
VALUES
	(7, 'Vaugh', 'William'),
	(7, 'Vaugh', 'Smith'),
	(6, 'Woods', 'Jane'),
	(6, 'Woods', 'Joseph'),
	(6, 'Wright', 'Adam'),
	(6, 'Wright', 'John')
;

SELECT
    STUFF(
        (SELECT '/' + Surname + ',' + STUFF(
            (SELECT '-' + Forename 
            FROM @T As T2 
            WHERE T2.Surname = T1.Surname 
            ORDER BY T2.Forename 
            FOR XML PATH(''), TYPE
        ).value('.', 'varchar(max)')
        , 1, 1, '')
        FROM @T As T1
		WHERE T1.ID = 6
        GROUP BY Surname
        ORDER BY Surname
        FOR XML PATH(''), TYPE
    ).value('.', 'varchar(max)')
    , 1, 1, '') As CombinedNames
;

-- Output:
-- Woods,Jane-Joseph/Wright,Adam-John




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: SQL server 12: Displaying column cell values in single cell Pin
Richard Deeming17-Feb-15 11:23
mveRichard Deeming17-Feb-15 11:23 
GeneralRe: SQL server 12: Displaying column cell values in single cell Pin
Swap917-Feb-15 22:49
Swap917-Feb-15 22:49 
QuestionSQL Optimization Pin
Chaminda Bandara16-Feb-15 21:59
professionalChaminda Bandara16-Feb-15 21:59 
AnswerRe: SQL Optimization Pin
Richard MacCutchan16-Feb-15 22:33
mveRichard MacCutchan16-Feb-15 22:33 
AnswerRe: SQL Optimization Pin
Corporal Agarn17-Feb-15 2:45
professionalCorporal Agarn17-Feb-15 2:45 
AnswerRe: SQL Optimization Pin
Mycroft Holmes17-Feb-15 15:03
professionalMycroft Holmes17-Feb-15 15:03 
GeneralRe: SQL Optimization Pin
Chaminda Bandara17-Feb-15 20:06
professionalChaminda Bandara17-Feb-15 20:06 
GeneralRe: SQL Optimization Pin
Mycroft Holmes18-Feb-15 2:14
professionalMycroft Holmes18-Feb-15 2:14 
QuestionVersioned data strategy Pin
LostTheMarbles15-Feb-15 22:08
professionalLostTheMarbles15-Feb-15 22:08 
AnswerRe: Versioned data strategy Pin
GuyThiebaut16-Feb-15 2:44
professionalGuyThiebaut16-Feb-15 2:44 
AnswerRe: Versioned data strategy Pin
Mycroft Holmes17-Feb-15 14:59
professionalMycroft Holmes17-Feb-15 14:59 
QuestionVB.NET MYSQL sum row values Pin
KipkoechE15-Feb-15 21:51
KipkoechE15-Feb-15 21:51 
AnswerRe: VB.NET MYSQL sum row values Pin
Richard MacCutchan15-Feb-15 23:11
mveRichard MacCutchan15-Feb-15 23:11 
QuestionMYSQL TABLE RECORDS TO ARRAY Pin
KipkoechE15-Feb-15 5:19
KipkoechE15-Feb-15 5:19 
AnswerRe: MYSQL TABLE RECORDS TO ARRAY Pin
Afzaal Ahmad Zeeshan15-Feb-15 5:41
professionalAfzaal Ahmad Zeeshan15-Feb-15 5:41 
GeneralRe: MYSQL TABLE RECORDS TO ARRAY Pin
KipkoechE15-Feb-15 5:46
KipkoechE15-Feb-15 5:46 
GeneralRe: MYSQL TABLE RECORDS TO ARRAY Pin
KipkoechE15-Feb-15 7:15
KipkoechE15-Feb-15 7:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.