Click here to Skip to main content
15,914,419 members
Home / Discussions / Database
   

Database

 
AnswerRe: Multiple Queries in one Stored procedure Pin
Abdulnazark9-Mar-15 7:08
Abdulnazark9-Mar-15 7:08 
AnswerRe: Multiple Queries in one Stored procedure Pin
deepankarbhatnagar11-Mar-15 0:02
professionaldeepankarbhatnagar11-Mar-15 0:02 
QuestionMYSQL SUM SEVERAL COLUMN VALUES Pin
KipkoechE17-Feb-15 10:29
KipkoechE17-Feb-15 10:29 
AnswerRe: MYSQL SUM SEVERAL COLUMN VALUES Pin
Richard Andrew x6417-Feb-15 11:13
professionalRichard Andrew x6417-Feb-15 11:13 
GeneralRe: MYSQL SUM SEVERAL COLUMN VALUES Pin
KipkoechE17-Feb-15 17:47
KipkoechE17-Feb-15 17:47 
AnswerRe: MYSQL SUM SEVERAL COLUMN VALUES Pin
Richard Andrew x6418-Feb-15 4:58
professionalRichard Andrew x6418-Feb-15 4:58 
GeneralRe: MYSQL SUM SEVERAL COLUMN VALUES Pin
KipkoechE18-Feb-15 11:30
KipkoechE18-Feb-15 11:30 
GeneralRe: MYSQL SUM SEVERAL COLUMN VALUES Pin
Richard Andrew x6419-Feb-15 4:55
professionalRichard Andrew x6419-Feb-15 4:55 
GeneralRe: MYSQL SUM SEVERAL COLUMN VALUES Pin
KipkoechE19-Feb-15 19:45
KipkoechE19-Feb-15 19:45 
QuestionSQL server 12: Displaying column cell values in single cell Pin
Swap917-Feb-15 2:35
Swap917-Feb-15 2:35 
SuggestionRe: SQL server 12: Displaying column cell values in single cell Pin
ZurdoDev17-Feb-15 2:54
professionalZurdoDev17-Feb-15 2:54 
GeneralRe: SQL server 12: Displaying column cell values in single cell Pin
Swap917-Feb-15 2:58
Swap917-Feb-15 2:58 
GeneralRe: SQL server 12: Displaying column cell values in single cell Pin
ZurdoDev17-Feb-15 3:00
professionalZurdoDev17-Feb-15 3:00 
GeneralRe: SQL server 12: Displaying column cell values in single cell Pin
Swap917-Feb-15 3:15
Swap917-Feb-15 3:15 
AnswerRe: SQL server 12: Displaying column cell values in single cell Pin
ZurdoDev17-Feb-15 3:24
professionalZurdoDev17-Feb-15 3:24 
GeneralRe: SQL server 12: Displaying column cell values in single cell Pin
Swap917-Feb-15 3:40
Swap917-Feb-15 3:40 
QuestionRe: SQL server 12: Displaying column cell values in single cell Pin
Eddy Vluggen17-Feb-15 4:38
professionalEddy Vluggen17-Feb-15 4:38 
AnswerRe: SQL server 12: Displaying column cell values in single cell Pin
Richard Deeming17-Feb-15 4:01
mveRichard Deeming17-Feb-15 4:01 
GeneralRe: SQL server 12: Displaying column cell values in single cell Pin
Swap917-Feb-15 5:16
Swap917-Feb-15 5:16 
GeneralRe: SQL server 12: Displaying column cell values in single cell Pin
Richard Deeming17-Feb-15 5:22
mveRichard Deeming17-Feb-15 5:22 
GeneralRe: SQL server 12: Displaying column cell values in single cell Pin
Swap917-Feb-15 5:36
Swap917-Feb-15 5:36 
GeneralRe: SQL server 12: Displaying column cell values in single cell Pin
Richard Deeming17-Feb-15 5:44
mveRichard Deeming17-Feb-15 5:44 
GeneralRe: SQL server 12: Displaying column cell values in single cell Pin
Swap917-Feb-15 5:51
Swap917-Feb-15 5:51 
GeneralRe: SQL server 12: Displaying column cell values in single cell Pin
Richard Deeming17-Feb-15 5:59
mveRichard Deeming17-Feb-15 5: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 10:23
mveRichard Deeming17-Feb-15 10:23 

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.