Hi @Vineet S
Try this:
DECLARE @sql VARCHAR(MAX)
DECLARE @view_elements VARCHAR(MAX)
SELECT @view_elements = ISNULL( @view_elements ,'') + Part
FROM (SELECT CONCAT(' UNION ALL ','select ','''',s.name,'.',v.name,'''',',', 'count(*) from ',s.name,'.',v.name) AS Part
FROM sys.views v INNER JOIN sys.schemas s ON s.schema_id = v.schema_id) S
GROUP BY Part
--PRINT @view_elements
SET @sql = ';WITH CTE AS ( SELECT '''' AS ViewName, 0 AS CountRows'+ @view_elements +') SELECT TOP(3) * FROM CTE WHERE CountRows > 40 ORDER BY CountRows DESC'
--PRINT (@sql)
EXEC (@sql)
Best regards,
Cosmog
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".