Restrict a character limit array in the LIKE

Asked

Viewed 114 times

1

I have a question about the LIKE of T-SQL. Is it possible to restrict by a number of equal characters to check how many addresses start equal and can end different? Sort of like this:

Where Endereco LIKE '[array10caracteres]%'

My goal is to arrive at a result more or less where a person’s address is:

Rua Comandante Inhares N 10
Rua Comandante Linhares LT 8 QD 150

The idea is that these two come up with a count or something

  • There are algorithms that compare string like Jaro-Winkler Distance (among others) I used once in Oracle and it worked well , but these comparisons are relative in case you look for addresses on the same street independent of the add-on (search for neighbors) ?

  • Yes... I seek neighbors and people from the same street.

  • The Jaro of Oracle returns a value of 93 for these two addresses, changing the address to "STREET COMMANDER KIRK LT 8 QD 150" gets 88 , question of maybe refine.

1 answer

4

You can restrict the value you use to the left of the LIKE:

WHERE LEFT(Endereco, 10) LIKE ...
  • I tried that, but it didn’t work. I don’t want to set an address what I want is for it to pick addresses with the same first 10 characters. You’ve made my point?

  • Want to compare all table addresses to each other?

  • Yes and group into one count those that have the 10 characters equal. To be able to pick up people from the same street but with different numbers and complements, understood?

  • With a GROUP BY LEFT(Endereco, 10) You can count how many people have the same address start. But you wouldn’t know what those people are, nor their full address. For this, you need a subquery. I think there is already an explanation about it here on the site, I will try to locate and pass you the link.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.