I have a table which shows common data for 5 days. Here is a query to create it.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ChartMast](
[ChartDate] [datetime] NOT NULL,
[ChartVal] [nvarchar](5) NULL,
[ChartVal1] [nvarchar](5) NULL,
[ChartVal2] [nvarchar](5) NULL,
[ChartVal3] [nvarchar](5) NULL,
[fromDt] [nvarchar](20) NULL,
[toDt] [nvarchar](20) NULL,
CONSTRAINT [PK_ChartMast] PRIMARY KEY CLUSTERED
(
[ChartDate] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
INSERT INTO ChartMast (ChartDate,ChartVal, ChartVal1, ChartVal2, ChartVal3,fromDt, toDt) Values ('2023-01-02 00:00:00.000', '80','477','80','190', '02/01/2023', '07/01/2023')
INSERT INTO ChartMast (ChartDate,ChartVal, ChartVal1, ChartVal2, ChartVal3,fromDt, toDt) Values ('2023-01-03 00:00:00.000', '55','780','55','889', '02/01/2023', '07/01/2023')
INSERT INTO ChartMast (ChartDate,ChartVal, ChartVal1, ChartVal2, ChartVal3,fromDt, toDt) Values ('2023-01-04 00:00:00.000', '34','410','34','225', '02/01/2023', '07/01/2023')
INSERT INTO ChartMast (ChartDate,ChartVal, ChartVal1, ChartVal2, ChartVal3,fromDt, toDt) Values ('2023-01-05 00:00:00.000', '27','128','27','505', '02/01/2023', '07/01/2023')
INSERT INTO ChartMast (ChartDate,ChartVal, ChartVal1, ChartVal2, ChartVal3,fromDt, toDt) Values ('2023-01-06 00:00:00.000', '07','280','07','188', '02/01/2023', '07/01/2023')
INSERT INTO ChartMast (ChartDate,ChartVal, ChartVal1, ChartVal2, ChartVal3,fromDt, toDt) Values ('2023-01-07 00:00:00.000', '06','145','06','448', '02/01/2023', '07/01/2023')
INSERT INTO ChartMast (ChartDate,ChartVal, ChartVal1, ChartVal2, ChartVal3,fromDt, toDt) Values ('2023-01-09 00:00:00.000', '53','117','53','269', '09/01/2023', '14/01/2023')
INSERT INTO ChartMast (ChartDate,ChartVal, ChartVal1, ChartVal2, ChartVal3,fromDt, toDt) Values ('2023-01-10 00:00:00.000', '77','260','77','466', '09/01/2023', '14/01/2023')
INSERT INTO ChartMast (ChartDate,ChartVal, ChartVal1, ChartVal2, ChartVal3,fromDt, toDt) Values ('2023-01-11 00:00:00.000', '24','346','24','680', '09/01/2023', '14/01/2023')
INSERT INTO ChartMast (ChartDate,ChartVal, ChartVal1, ChartVal2, ChartVal3,fromDt, toDt) Values ('2023-01-12 00:00:00.000', '48','590','48','115', '09/01/2023', '14/01/2023')
INSERT INTO ChartMast (ChartDate,ChartVal, ChartVal1, ChartVal2, ChartVal3,fromDt, toDt) Values ('2023-01-13 00:00:00.000', '70','124','70','244', '09/01/2023', '14/01/2023')
INSERT INTO ChartMast (ChartDate,ChartVal, ChartVal1, ChartVal2, ChartVal3,fromDt, toDt) Values ('2023-01-14 00:00:00.000', '85','440','85','853', '09/01/2023', '14/01/2023')
So, I have to group data on fromDt and toDt column.
Like I need all data of fromDt and toDt in one row only so it will show 6 columns in single row
likewise it will show only 2 rows
How could I do it?