dynamically How to convert rows to columns in sql server : I want to convert rows to columns dynamically, for sample data I have given below query.




create table testtable(
tableid int primary key identity(1,1),
tableDatetime datetime,
names  varchar(50),
tablevalue  decimal(18,9)
)

go

insert into testtable
select '2019-06-13 13:56:39.117', 'test1',23.45 union all
select '2019-06-13 13:56:39.117', 'test2',33.45 union all
select '2019-06-13 13:56:39.117', 'test3',10.45 union all
select '2019-06-13 13:56:39.117', 'test4',90.45 union all
select '2019-06-13 14:01:41.280', 'test1',33.45 union all
select '2019-06-13 14:01:41.280', 'test2',53.45 union all
select '2019-06-13 14:01:41.280', 'test3',41.45 union all
select '2019-06-13 14:01:41.280', 'test4',93.45 union all
select '2019-06-13 14:06:42.363', 'test1',30.45 union all
select '2019-06-13 14:06:42.363', 'test2',13.45 union all
select '2019-06-13 14:06:42.363', 'test3',23.45 union all
select '2019-06-13 14:06:42.363', 'test4',73.45  

go
select * from testtable

I want to convert data into below format

Datetime		test1	test2		test3		test4
2019-06-13 13:56:39  	23.45	33.45		10.45		90.45
2019-06-13 14:01:41	33.45	53.45		41.45		93.45
2019-06-13 14:06:42	30.45	13.45		23.45		73.45