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

  • Home
  • SEARCH
  • 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 8242943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:20:26+00:00 2026-06-07T21:20:26+00:00

Possible Duplicate: Combining rows of queried results by unique identifier? I have two tables

  • 0

Possible Duplicate:
Combining rows of queried results by unique identifier?

I have two tables in Sql Server 2008, like below

Table1

       DealNum            DealVresion            Value

        1000                   1                 100
        1000                   2                 200
        1000                   3                 150  
        1000                   4                 130
        1001                   2                  70
        1003                   5                 160
        1003                   0                 120                    

Table 2

     DealNum            DealVersion              Name 

     1000                    1                   John
     1000                    1                   Bob
     1000                    2                   John
     1000                    2                   Merle
     1000                    3                   Bob
     1000                    3                   Bob
     1000                    5                   Bob
     1001                    2                   Smith
     1001                    2                   stone
     1002                    8                   Andrew
     1003                    5                   Smith
     1003                    0                   Martin
     1003                    0                   Narine

Now I want a left join on these two tables based on

     (T1.Dealnum= T2.Dealnum) and (T1.Deal Version = T2.Deal Version)

and I want the Name from Table2 to be concatenated so that it won’t show any duplicates in DealNum.

Result Required:

         DeaLNum           Deal Version          Value          Name

          1000                  1                 100           Jhon,Bob
          1000                  2                 200           John,Merle
          1000                  3                 150           Bob
          1000                  4                 130           NULL
          1001                  2                 70            Smith,Stone                  
          1003                  0                 120           Martin,Narine
          1003                  5                 160           Smith

It has to concatenate the names column for the DealNum and version.
If the same dealNum and Version has the same name then no need to Concatenate(ex: 1000 – 3)

Thanks In advance
Harry

  • 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-06-07T21:20:28+00:00Added an answer on June 7, 2026 at 9:20 pm

    You can do this by creating a user defined function, don’t know if it can be done in a single select statement:

        create function getNameList(@dealnum int, @dealversion int) returns nvarchar(max)
        begin
        declare @name varchar(max)
    
        select  @name = coalesce(@name + ', ','') + name
        from    (select distinct name from table2 where dealnum = @dealnum and dealversion = @dealversion) t1
    
        return @name
        end
    

    then:

        select  distinct
                t1.dealNum,
                t1.dealVersion,
                t1.value,
                dbo.getNameList(t1.dealNum, t1.dealversion)
        from    table1 t1 join table2 t2 on t1.dealnum = t2.dealnum and t1.dealversion = t2.dealversion
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: combining two lamba expressions in c# I have two following expressions: Expression<Func<string,
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: Combining several database table together? I want from two database table get
Possible Duplicate: Best way to stop SQL Injection in PHP I would like to
Possible Duplicate: Compiling a java program into an exe Hi, I'd like to convert
Possible Duplicate: How to get the address of an overloaded member function? I have
Possible Duplicate: regex for URL including query string I have a text or message.
Possible Duplicate: thread with multiple parameters How does one thread a sub with two
Possible Duplicate: How can I combine multiple rows into a comma-delimited list in Oracle?
Possible Duplicate: How to call a JavaScript function from PHP? I have a php

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.