Sherlock Holmes quotes a few writers in the chronicles we have of him. He also quotes a few anonymous writers as well. And then there's the thing that doesn't make a lot of sense: Holmes and Humpty Dumpty.
Holmes paraphrase the rhyme in "The Bruce Partington Plans," a case which occurred in 1895. So we think, "Oh, he learned the rhyme in childhood!" But Sherlock Holmes is paraphrasing the modern version of the verse.
"I'm afraid," said Holmes, smiling, "that all the queen's horses and all the queen's men cannot avail in this matter."
Looking at what was available when Holmes was a lad, one finds things like "Threescore men and threescore more, cannot place Humpty Dumpty as he was before," and "Forty Doctors and forty wrights, couldn't put Humpty Dumpty to rights!"
Finding a version with "All the king's horses and all the king's men, couldn't put Humpty Dumpty together again" prior to 1900 is a difficult task. A look at Google's Ngram viewer even shows that "Humpty" is not being referenced all that much in 1895.