October 5, 2007 at 12:58 pm
I want to ignore all records in a table where a field, say Address, contains 2 or more (not necessarily consecutive) spaces. I want to process records with Address containing 0 or 1 spaces. How would you do this in t-sql? Regardless of the number of spaces in Address I don't want to modify the Address field itself.
TIA,
Barkingdog
October 5, 2007 at 3:00 pm
select *
from yourtable
where len(address) - len( replace(address,' ','')) <= 1
* Noel
October 5, 2007 at 8:41 pm
Amazingly simple! 3 woofs and a tail wag.
I was under the impression that using "replace", even as a test, would actually cause the replacement to take place in the string being tested. I thought of your algorithm but was convinced it would not work because of my, apparently, false "impression." I couldn't and didn't do it without your help.
Thanks,
Barkingdog
October 6, 2007 at 8:04 pm
When in doubt, simple tests will keep you from barking up the wrong tree or missing a perfectly good fire hydrant 😛
--Jeff Moden
Change is inevitable... Change for the better is not.
October 7, 2007 at 12:11 pm
Or you can use this, with space instead of backslash
N 56°04'39.16"
E 12°55'05.25"
October 7, 2007 at 4:12 pm
I never met a fire hydrant I didn't like.
Woof woof!
Thanks.
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply