Is there a way to find the highest voted comment on a particular SE site?

0

Please login or register to vote for this query.

(click on this box to dismiss)

https://meta.stackexchange.com/questions/98125/is-there-a-way-to-find-the-highest-voted-comment-on-a-particular-se-site

Meta Stack Exchange

Q&A for meta-discussion of the Stack Exchange family of Q&A websites

declare @sql nvarchar(max)

create table #result (site sysname
                    , hostname sysname
                    , displayname nvarchar(150)
                    , userid integer
                    , commentid integer
                    , comment nvarchar(600)
                    , score integer
                    , creationdate datetime)

select @sql = N'insert into #result' + STRING_AGG(concat(N'
select site
     , hostname
     , displayname
     , uid
     , cid
     , text
     , score
     , creationdate
from (
select top 1000 ''', name ,N''' as site
     , ''',hostname ,N''' hostname
     , u.displayname
     , u.id uid
     , c.id cid
     , c.text
     , c.score
     , c.creationdate
from ', quotename(name), N'.dbo.comments c
left outer join ', quotename(name), N'.dbo.users u on
  c.userid = u.id
order by score desc
) data
'),N' 
union all')
from (select convert(nvarchar(max),name) name
    -- , convert(nvarchar(max),sitename)  sitename
    -- , meta
    -- , domain
     ,  concat( 
        -- based on an idea from Glorfindel 
        -- https://meta.stackexchange.com/a/321181
        (case sitename
        WHEN 'Audio' THEN 'video'
        WHEN 'Beer' THEN 'alcohol'
        WHEN 'CogSci' THEN 'psychology'
        WHEN 'Garage' THEN 'mechanics'
        WHEN 'Health' THEN 'medicalsciences'
        WHEN 'Moderators' THEN 'communitybuilding'
        WHEN 'Photography' THEN 'photo'
        WHEN 'Programmers' THEN 'softwareengineering'
        WHEN 'Vegetarian' THEN 'vegetarianism'
        WHEN 'Writers' THEN 'writing'
        WHEN 'Br' THEN 'pt'
        WHEN 'Mathoverflow' THEN concat((meta+'.'), sitename)
        ELSE case when sitename = domain then null else sitename end
        end +'.')
        , (case 
           when sitename <> 'mathoverflow' then (meta+'.') 
           else null 
           end) 
        , (case 
           when sitename <> 'mathoverflow' then concat((domain + '.'), 'com') 
           else 'net' 
           end)
        ) hostname
from (
select name
, case parsename(name,1) 
  when 'Meta' then parsename(name,2)
  else parsename(name,1) 
  end [sitename]
, case parsename(name,1) 
  when 'Meta' then 'meta'
  else null
  end [meta]
  , coalesce(parsename(name,3), parsename(name,2)) [domain]
from sys.databases
where database_id > 5
-- (name not like '%.Meta' or name = 'StackExchange.Meta')
) dbs
) dbsall

exec (@sql)


-- https://meta.stackexchange.com/questions/332237/documentation-for-stack-exchange-engine-urls
-- comment link idea fron Glorfindel
select top 1000 
       site
     , concat('https://'
       , hostname
       , '/posts/comments/'
       , commentid
       , '|'
       , comment
       ) [Link to Comment]
     , concat('https://'
       , hostname
       , '/users/'
       , userid
       , '|'
       , coalesce(displayname, '<?>')
       ) [Owning user]
     , creationdate
     , score
from #result
order by score desc

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results