Using below query to collect fragmentation data from SSR. You will need to replace a few literals with your own values
USE [SpotlightStatisticsRepository]
EXEC [spotlight_rt_get_batch_data]
@start_date = N'jan 1 2018',
@end_date = N'dec 1 2018',
@domain_name_list = N'{{domain}}',
@monitoredobject_list = N'{{instance1}},{{instance2}} ,
@table_name = N'FragmentationByIndex',
@column_list = N'AllocUnitTypeDesc,AverageFragmentation,DBName,Disabled,IndexName,Key,OwnerName,PageCount,PartitionNumber,TableName,Type,TypeEnum'
Replace
Database name in the USE statement if the SSR database name is different
Start_date and end_date with the date range required.
{{domain}} with a value from this select
select domain_description from spotlight_domains
If you have more than one Diagnostic Server writing to the same SSR you can include them in the parameter by separating them by commas.
{{instance1}} and {{intance2}} with the connection names you want to report on. These are in the internal format that Spotlight uses. The format is host_instance_sqlserver .
Use this select to see a list of names and then use values from the monitored_object_name column
select monitored_object_display_name, monitored_object_name from spotlight_monitored_objects
where monitored_object_name like '%_sqlserver'
order by monitored_object_display_name