I am trying to write a query for Stack Exchange’s very own Data Explorer. This query will create a temporary table containing a list of commonly misspelled words and their proper spellings and then search through the posts to find them.
Here is what I have so far (minus the comments):
DECLARE @SpellingMistakes TABLE (wrong VARCHAR(255), right VARCHAR(255))
INSERT INTO @SpellingMistakes (wrong, right)
VALUES ('ubunut', 'ubuntu')
SELECT Id as [Post Link]
FROM Posts
WHERE
...
And that’s where I get stuck – in the WHERE clause. I need some way of saying "if Posts.Body contains any of @SpellingMistakes.wrong". However, I’m not sure how to do that.
Note: the data explorer uses Microsoft SQL Server 2008 R2.
I don’t know MS SQL, but most SQL implementations have a ‘LIKE’ equivalent. So in that case, you could join the two tables and use LIKE in the JOIN condition.
EDIT: Assuming
Postsis a large table (andSpellingMistakesis not too small either), this will take a lot of resources. One way to tackle this is to split tablePostsinto smaller subsets and construct multiple statements.And so on.