Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7435097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:00:14+00:00 2026-05-29T10:00:14+00:00

I am using SQL server 2008, and I need to make a common delimeted

  • 0

I am using SQL server 2008, and I need to make a common delimeted list of a column. I know how to do it, but I need this time while I use analytical function, I mean I don’t want to use group by clause.
Since I will also select the records in outer query “where row_num=1“

Here is the query:

SELECT UserId
      ,ProductList
      ,Value
  FROM
  (
SELECT p.UserId 
     ,p.Value
     , ROW_NUMBER()OVER (PARTITION BY p.UserId ORDER BY p.RecordCreateDate asc) AS 'row_num'
     --here I need a solution  OVER (PARTITION BY p.UserId) AS 'ProductList'
  FROM Products p
       INNER JOIN
       Users u
       ON p.UserId = u.Id
       ) result
 WHERE result.row_num = 1

Users data:

Id       Name      ....
 1       John
 2       Anton
 3       Craig

Products data:

Id      UserId      Name     RecordCreateDate   Value
 1           1         a           21.12.2012      10
 2           1         b           11.12.2012      20
 3           1         c           01.12.2012      30
 4           2         e           05.12.2012      40
 5           2         f           17.12.2012      50
 6           3         d           21.12.2012      60 
 7           3         i           31.12.2012      70

I need a result such as:

UserId     ProductList      Value
     1           a,b,c         30
     2             e,f         40
     3             d,i         60

Thanks for your help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:00:15+00:00Added an answer on May 29, 2026 at 10:00 am

    Just for completeness. Remove the # symbols for your actual solution.

    SET NOCOUNT ON;
    
    CREATE TABLE #users
    (
        Id INT,
        Name VARCHAR(32)
    );
    
    INSERT #users VALUES
    (1,'John'),
    (2,'Anton'),
    (3,'Craig');
    
    CREATE TABLE #products
    (
        Id INT,
        UserId INT,
        Name VARCHAR(32),
        RecordCreateDate DATE,
        Value INT
    );
    
    INSERT #products VALUES
    (1,1,'a','2012-12-21',10),
    (2,1,'b','2012-12-11',20),
    (3,1,'c','2012-12-01',30),
    (4,2,'e','2012-12-05',40),
    (5,2,'f','2012-12-17',50),
    (6,3,'d','2012-12-21',60), 
    (7,3,'i','2012-12-31',70);
    

    The query:

    ;WITH x AS 
    (
        SELECT UserId, Value, 
            row_num = ROW_NUMBER() OVER 
            (
                  PARTITION BY UserId 
                  ORDER BY RecordCreateDate
            )
            FROM #products
    )
    SELECT
      x.UserId,
      u.Name,
      ProductList = STUFF((
         SELECT ',' + Name
            FROM #Products AS p 
            WHERE p.UserId = x.UserId 
            FOR XML PATH(''), 
            TYPE).value(N'./text()[1]', N'varchar(max)'),1,1,''),
      x.Value
    FROM x
    INNER JOIN #users AS u
    ON x.UserId = u.Id
    WHERE x.row_num = 1;
    

    Then clean up:

    DROP TABLE #users, #products;
    

    Results:

    UserId  Name    ProductList  Value
    1       John    a,b,c        30
    2       Anton   e,f          40
    3       Craig   d,i          60
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using SQL Server 2008 and I need to make a VARCHAR field bigger,
Using SQL Server 2008, I need to select this XML into a Table. I
I don't know much (really anything) about SQL Server 2008, but I just need
I am using SQL Server 2008 and I need to select all data from
I am using SQL Server 2008 Enterprise version. I want to know if I
We are currently using SQL Server 2008 Express Edition, but would like to upgrade
I am using SQL Server 2008. I am writing a query where I need
I need to backup database (using SQL Server 2008 R2). Size of db is
Using SQL Server 2008, is there a way to allow inserts to a table
I'm using SQL Server 2008 with Advanced Services on my Vista Home Premium. I'd

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.