How to Merge rows in Sql

Aypn CNN 446 Reputation points
2021-06-03T16:47:25.527+00:00

Hi Friends,

This is my Table,

Create Table #Temp (DueDate1 int, DueDate2 int, DueDate3 int, DueDate4 int, DueDate5 int)  
Insert into #Temp (DueDate1, DueDate2, DueDate3, DueDate4, DueDate5) Values(1,0,0,0,5)  
Insert into #Temp (DueDate1, DueDate2, DueDate3, DueDate4, DueDate5) Values(1,0,0,4,0)  
Insert into #Temp (DueDate1, DueDate2, DueDate3, DueDate4, DueDate5) Values(1,0,3,4,5)  
  
Select * From #Temp  
  

Expected result is

102127-image.png

Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,633 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,494 questions
0 comments No comments
{count} votes

Accepted answer
  1. Hafeez Uddin 296 Reputation points
    2021-06-03T16:58:07.737+00:00

    You can try this.
    Select max(DueDate1),max(DueDate2) ,max(DueDate3) ,max(DueDate4) ,max(DueDate5) From #Temp

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.