A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi @Murari Ram ,
The column and data in your expected output do not correspond, so all the data is returned in my code, you can replace the * in the select statement with the column you need to return.
Please refer to:
CREATE TABLE [dbo].[temp1](
[Prid] [varchar](20) NOT NULL,
[Sponsor] [varchar](80) NULL,
[ProjectManager] [varchar](100) NULL,
[Country_Name] [varchar](200) NOT NULL,
[cntid] [int] NOT NULL,
[RolloutStartDate] [date] NULL,
[RolloutEndDate] [date] NULL,
[CountryImpact] [bit] NULL,
[StartDateatRisk] [bit] NULL,
[EndDateatRisk] [bit] NULL
) ON [PRIMARY]
GO
insert into temp1 values('KT1','KT','Siva Hanuma','France',2,'2020-09-08','2022-03-04',0,0,0)
go
insert into temp1 values('KT1','KT','Siva Hanuma','US',1,'2020-09-08','2022-03-04',0,0,0)
go
insert into temp1 values('KT1','KT','Siva Hanuma','Germany',3,'2020-09-08','2022-03-04',0,0,0)
with cte1
as(select PRID, Sponsor, ProjectManager,cntid Francecntid ,RolloutStartDate FranceRolloutStartDate, RolloutEndDate FranceRolloutEndDate,
CountryImpact FranceCountryImpact,StartDateatRisk FranceStartDateatRisk,EndDateatRisk FranceEndDateatRisk
from temp1 where Country_Name='France')
,cte2 as(select PRID,cntid UScntid ,RolloutStartDate USRolloutStartDate, RolloutEndDate USRolloutEndDate,
CountryImpact USCountryImpact,StartDateatRisk USStartDateatRisk,EndDateatRisk USEndDateatRisk from temp1 where Country_Name='US')
,cte3 as(select PRID,cntid Germanycntid ,RolloutStartDate GermanyRolloutStartDate, RolloutEndDate GermanyRolloutEndDate,
CountryImpact GermanyCountryImpact,StartDateatRisk GermanyStartDateatRisk,EndDateatRisk GermanyEndDateatRisk from temp1 where Country_Name='Germany')
select * from cte1 c1
join cte2 c2
on c1.Prid=c2.Prid
join cte3 c3
on c2.Prid=c3.Prid
drop table temp1
Best Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.