Merge two retrived rows by variable

I have the following issue. I have declared a variable based on ID value, but there are two different values that have my data. This is what I retreive:

    entry_template_id   entry_template_name book_display_name   entry_count value_count null_value_count    null_percentage followed_value_count    followed_null_value_count   followed_null_percentage    
                   9    Loading             Reporting            10            530           78              0.147169811320      520                      78                         0.150000000000 
                   19   Loading             Reporting            1              53            8              0.150943396226       53                       8                         0.150943396226

I want to retrive just one row with ID like (9, 19), same template_name, same display_name, SUM (entry_count), SUM(value_count), SUM(null_value_count), AVG(null_percentage), SUM(followed_value_count), SUM(followed_nulls_value_count), AVG(followed_null_percentage).

  • Retrieve fields schema in Visual Studio of stored procedure which uses temp tables
  • Find no of days remaining on current month from given date
  • Is it better to use an uniqueidentifier(GUID) or a bigint for an identity column?
  • How to convert DateTime to TimeSpan in Entity Framework query
  • How to check are there JSON Functions by SQL query?
  • Login failed for SQL Server user through page
  • Can you please help me with the syntax?

    Thank you!

    One Solution collect form web for “Merge two retrived rows by variable”

    Provided that you want to group by name, this should work:

    STUFF((SELECT ', ' + CAST(entry_template_id AS varchar(50))
           FROM Entries t2 where t1.entry_template_name = t2.entry_template_name 
           FOR XML PATH('')), 1, 2, '') Ids, 
    MAX(entry_template_name) entry_template_name, 
    MAX(book_display_name) book_display_name, 
    SUM(entry_count) entry_count, SUM(value_count) value_count, 
    SUM(null_value_count) null_value_count, 
    AVG(null_percentage) null_percentage, 
    SUM(followed_value_count) followed_value_count, 
    SUM(followed_null_value_count) followed_null_value_count, 
    AVG(followed_null_percentage) followed_null_percentage
    FROM Entries t1
    GROUP BY entry_template_name

    See this question for further explanation.

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.