How to merge multiple records into one using SQL SERVER?

2

I need this table:

Be this: (edit it as an image using paint to show as an example)

The data will always have the same 'serverName', DATE and TIME in common

    
asked by Ricardo Soria 04.10.2018 в 18:48
source

2 answers

2

What you must do is group by certain columns. In this case, for serverName , Date and Time , for example, this query would return a result like the one you expect:

with
Datos as (
select 16 idse, 'LSTKAG72544' serverName, cast('20180928' as date) [DATE], CAST('17:09:59' as time) [TIME], null SQLBrowser, 'Running' W3SVC, null wscsvc
union all
select 17 idse, 'LSTKAG72544' serverName, cast('20180928' as date) [date], CAST('17:09:59' as time) [time], null SQLBrowser, null W3SVC, 'Running' wscsvc
union all
select 18 idse, 'LSTKAG72544' serverName, cast('20180928' as date) [date], CAST('17:09:59' as time) [time], 'Running' SQLBrowser, null W3SVC, null wscsvc
)
select   min(idse) idse
       , serverName
       , [DATE]
       , [TIME]
       , min(SQLBrowser) SQLBrowser
       , min(W3SVC) W3SVC
       , MIN(wscsvc) wscsvc
  from Datos
 group by serverName, [DATE], [TIME];
    
answered by 04.10.2018 / 18:57
source
-1

Takes the records to a Database and then performs the query with the GROUP BY statement and you put it in the table.

Welcome to StackoverFlow in Spanish, sorry but use the Translator to answer you ...

    
answered by 04.10.2018 в 18:57