All post links to and from a given post

1

Please login or register to vote for this query.

(click on this box to dismiss)

Chess

Q&A for serious players and enthusiasts of chess

create table #PostLinkTypes (
  Id int primary key,
  Name nvarchar(40) not null
)
insert into #PostLinkTypes values (1, 'Linked'), (3, 'Duplicate')

select
  PostLinks.Id as [Link ID],
  CreationDate as [Created],
  '->' as [Dir],
  RelatedPostId as [Post Link],
  coalesce(Type.Name, 'Unknown ' + cast(LinkTypeId as nvarchar(40))) as [Type]
from
  PostLinks
  left join #PostLinkTypes as Type on Type.Id = LinkTypeId
where
  PostId = ##PostId:int##

union all

select
  PostLinks.Id as [Link ID],
  CreationDate as [Created],
  '<-' as [Dir],
  PostId as [Post Link],
  coalesce(Type.Name, 'Unknown ' + cast(LinkTypeId as nvarchar(40))) as [Type]
from
  PostLinks
  left join #PostLinkTypes as Type on Type.Id = LinkTypeId
where
  RelatedPostId = ##PostId:int##
  and PostId != ##PostId:int##  -- don't list self-links twice

Enter Parameters

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