View a single comment based on ID or URL

3

Please login or register to vote for this query.

(click on this box to dismiss)

Ebooks

Q&A for ebook publishers and readers

DECLARE @TextToFind nvarchar(100) = '#comment';
DECLARE @CommentId int = ##CommentId?0##;
DECLARE @RawLink nvarchar(512) = '##RawLink?null##';
DECLARE @HashTagIndex int;
DECLARE @RawCommentId nvarchar(512);
DECLARE @UnderscoreIndex int;
If @CommentId = 0 Begin
    Select @HashTagIndex = CharIndex(@TextToFind, @RawLink);
    If @HashTagIndex<1 Begin
        Select 'Invalid or not supported comment URL, sorry';
    End Else Begin
        Select @RawCommentId = SubString(@RawLink, 
            @HashTagIndex + Len(@TextToFind), 100);
        Select @UnderscoreIndex = CharIndex('_', @RawCommentId);
        If @UnderscoreIndex>0 Begin
            Select @CommentId = Convert(int, 
                SubString(@RawCommentId, 1, @UnderscoreIndex - 1));
        End Else Begin
            Select @CommentId = Convert(int, @RawCommentId);
        End
    End
End
Select PostId as [Post Link], Score, [Text], CreationDate, UserId As [User Link]
From Comments
Where Id=@CommentId

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results