Click here to Skip to main content
15,913,467 members
Home / Discussions / Database
   

Database

 
GeneralRe: Equivalent in MS Sql Pin
jschell14-Dec-11 9:26
jschell14-Dec-11 9:26 
GeneralRe: Equivalent in MS Sql Pin
Shameel15-Dec-11 7:27
professionalShameel15-Dec-11 7:27 
GeneralRe: Equivalent in MS Sql Pin
SilimSayo15-Dec-11 11:00
SilimSayo15-Dec-11 11:00 
GeneralRe: Equivalent in MS Sql Pin
jschell16-Dec-11 8:34
jschell16-Dec-11 8:34 
JokeRe: Equivalent in MS Sql Pin
SilimSayo16-Dec-11 14:31
SilimSayo16-Dec-11 14:31 
GeneralRe: Equivalent in MS Sql Pin
Shameel20-Dec-11 2:51
professionalShameel20-Dec-11 2:51 
QuestionGROUP BY and listing rows in an aggrigate Pin
nallelcm13-Dec-11 5:44
nallelcm13-Dec-11 5:44 
AnswerRe: GROUP BY and listing rows in an aggrigate Pin
Eddy Vluggen13-Dec-11 7:07
professionalEddy Vluggen13-Dec-11 7:07 
nallelcm wrote:
here is my problem.

I included a script that generates your demo-data; just copy and paste to give it a try.
SQL
-- Just to be on the safe side
BEGIN TRANSACTION

-- The sample table
CREATE TABLE Employees
(
     id       INT
    ,[name]   VARCHAR(50)  
    ,position VARCHAR(50)
);

-- The sample data
INSERT INTO Employees (id, [name], position) 
      SELECT 1,    'bob',     'sales'
UNION SELECT 2,    'joe',     'sales'
UNION SELECT 3,    'mark',    'management'
UNION SELECT 4,    'jane',    'management'
UNION SELECT 5,    'julie',   'it'
UNION SELECT 6,    'donald',  'sales'

-- Making a list of unique positions
SELECT DISTINCT position 
           INTO #Positions 
           FROM Employees;

-- Select all positions, using a FOR XML subquery to fetch the members
-- The REPLACE and SUBSTRING functions are used to remove the XML-tags
SELECT position, 
       SUBSTRING(names, 0, LEN(names) - LEN(', '))
FROM   (SELECT position,
               REPLACE(REPLACE((SELECT [name]
                                FROM   employees e
                                WHERE  e.position = p.position
                                FOR XML AUTO), '<E name="', ''), '"/>', ', ') AS
               names
        FROM   #positions p) AS tmp_cte;  

-- Undo everything we just did
ROLLBACK

Output on my machine;
Txt
position                       names
---------------                ------------------
it                             julie
management                     mark, jane
sales                          bob, joe, donald

Bastard Programmer from Hell Suspicious | :suss:

GeneralRe: GROUP BY and listing rows in an aggrigate Pin
nallelcm13-Dec-11 7:26
nallelcm13-Dec-11 7:26 
AnswerRe: GROUP BY and listing rows in an aggrigate Pin
Eddy Vluggen13-Dec-11 7:44
professionalEddy Vluggen13-Dec-11 7:44 
AnswerRe: GROUP BY and listing rows in an aggrigate Pin
Eddy Vluggen13-Dec-11 8:34
professionalEddy Vluggen13-Dec-11 8:34 
GeneralRe: GROUP BY and listing rows in an aggrigate Pin
nallelcm13-Dec-11 8:51
nallelcm13-Dec-11 8:51 
GeneralRe: GROUP BY and listing rows in an aggrigate Pin
Eddy Vluggen13-Dec-11 9:34
professionalEddy Vluggen13-Dec-11 9:34 
Questioncolums to single row Pin
Ramkumar_S12-Dec-11 18:29
Ramkumar_S12-Dec-11 18:29 
AnswerRe: colums to single row Pin
_Damian S_12-Dec-11 19:43
professional_Damian S_12-Dec-11 19:43 
AnswerRe: colums to single row Pin
SilimSayo13-Dec-11 3:13
SilimSayo13-Dec-11 3:13 
AnswerRe: colums to single row Pin
gvprabu22-Dec-11 1:45
gvprabu22-Dec-11 1:45 
Questionerror has occurred while establishing a connection Pin
Member 808991411-Dec-11 23:54
Member 808991411-Dec-11 23:54 
AnswerRe: error has occurred while establishing a connection Pin
Satheesh154612-Dec-11 1:20
Satheesh154612-Dec-11 1:20 
AnswerRe: error has occurred while establishing a connection Pin
thatraja12-Dec-11 1:58
professionalthatraja12-Dec-11 1:58 
QuestionSQL Server Management Studio R2 (varchar(MAX)) Pin
Framework .l.11-Dec-11 18:13
Framework .l.11-Dec-11 18:13 
AnswerRe: SQL Server Management Studio R2 (varchar(MAX)) Pin
Mycroft Holmes11-Dec-11 19:04
professionalMycroft Holmes11-Dec-11 19:04 
GeneralRe: SQL Server Management Studio R2 (varchar(MAX)) Pin
Framework .l.11-Dec-11 19:26
Framework .l.11-Dec-11 19:26 
GeneralRe: SQL Server Management Studio R2 (varchar(MAX)) Pin
Mycroft Holmes11-Dec-11 19:40
professionalMycroft Holmes11-Dec-11 19:40 
GeneralRe: SQL Server Management Studio R2 (varchar(MAX)) Pin
Framework .l.11-Dec-11 20:47
Framework .l.11-Dec-11 20:47 

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.