Posts that end with the displayname of the user

0

Please login or register to vote for this query.

(click on this box to dismiss)

http://stackoverflow.com/questions/7394276/sql-best-way-to-compare-the-end-of-a-string-use-right-like-or-other for meta: http://meta.stackexchange.com/questions/109536/why-is-this-data-explorer-query-timing-out-and-or-triggering-a-something-is-wro

Stack Overflow

Q&A for professional and enthusiast programmers

/*
body like '%'+ displayname+'</p>' is notoriously slow
a reverse column with an index would be superb but 
a charindex works as well.
remember that most posts ends with a </p> and a char(10)...

I left both methods in here as an example
*/
select top 500 
       posts.Id as [Post Link] 
       , right(body,10)
       , ascii(right(body,1))
from 
       posts
join 
       users 
       on posts.OwnerUserId=users.id
where -- charindex(users.displayname, posts.body) 
    -- = len(posts.body) - len(users.displayname) - 4 -- </p> is 4 chars
body like '%'+ displayname+ N'</p>'+char(10)
and posttypeid =1 -- questions

Enter Parameters

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