I know of one writer who worked on his book for eleven years before querying--tweaking, rewriting, and generally being afraid of rejection. I know of another writer who started querying the instant she typed "the end" at the end of the manuscript--before revising at all, without even looking over the manuscript.
We both know that both of those people were foolish in their approach.
But how long should we query? I queried my first manuscript for over a year--I queried my last one for a month before pulling it out of submissions for rewrites.
BookEnds, LLC has what I think is the best advice--and what I have fallen into as practice just by chance.
In short: write a novel, revise the novel, being querying, begin writing new novel. By the time you finish the new novel, pull out the original. Repeat until success.