473,383 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Identifying Repeating values in a string

The address field in my User table has data like:

1905 1905 S OAK ST
314 ROSSELL AVE
252 252 HIGH MEADOWS ST
1402 1402 TOWNSEND CT
2021 MAHAN AVE
347 347 N 7 AVE

As you see we have repeating House #s here. I would like to write a query to:

1.Give me addresses and its counts where the house # has been repeated.
2.Correct the repeating house # to have a single house # in the Street Address

Please help me out here.
Apr 5 '07 #1
1 2805
iburyak
1,017 Expert 512MB
Try this:

1. Create test table and insert data:
[PHP]
create table table1 (address varchar(30))
insert into table1 values ('1905 1905 S OAK ST')
insert into table1 values ('314 ROSSELL AVE')
insert into table1 values ('252 252 HIGH MEADOWS ST')
insert into table1 values ('1402 1402 TOWNSEND CT')
insert into table1 values ('2021 MAHAN AVE')
insert into table1 values ('347 347 N 7 AVE')[/PHP]

2. Create function:

[PHP]CREATE FUNCTION fnSplit(@String nvarchar(4000), @Delimiter char(1))
RETURNS varchar(100)
AS

BEGIN
DECLARE @Results TABLE (Items nvarchar(200))

DECLARE @INDEX INT
DECLARE @SLICE nvarchar(4000)
DECLARE @DuplicateAddr varchar(50)

SELECT @INDEX = 1
WHILE @INDEX !=0


BEGIN
-- GET THE INDEX OF THE FIRST OCCURENCE OF THE SPLIT CHARACTER
SELECT @INDEX = CHARINDEX(@Delimiter,@STRING)
-- NOW PUSH EVERYTHING TO THE LEFT OF IT INTO THE SLICE VARIABLE
IF @INDEX !=0
SELECT @SLICE = LEFT(@STRING,@INDEX - 1)
ELSE
SELECT @SLICE = @STRING
-- PUT THE ITEM INTO THE RESULTS SET
INSERT INTO @Results(Items) VALUES(@SLICE)
-- CHOP THE ITEM REMOVED OFF THE MAIN STRING
SELECT @STRING = RIGHT(@STRING,LEN(@STRING) - @INDEX)
-- BREAK OUT IF WE ARE DONE
IF LEN(@STRING) = 0 BREAK
END
Select @DuplicateAddr = Items
from @Results
group by Items
having count(*) > 1

RETURN @DuplicateAddr
END [/PHP]

3. Query table:

[PHP]Select *, Replace(address, DupAddress + ' ' + DupAddress, DupAddress) ResultAddress
From (
select address, dbo.fnSplit(address, ' ') DupAddress
from table1 ) a
Where Not DupAddress is null[/PHP]

Hope it helps.
Good Luck.
Apr 5 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: hokiegal99 | last post by:
This is not really a Python-centric question, however, I am using Python to solve this problem (as of now) so I thought it appropiate to pose the question here. I have some functions that search...
4
by: Dean | last post by:
I am a developer who works with MS SQL Server a lot, but I'm far from an expert. I am revamping an appointment scheduling system that allows for appointments to reoccur daily, weekly, monthly and...
0
by: dino07 | last post by:
Hi All, I am currently trying to do the following: 1. insert a value into a repeating table from a drop-down list( secondary storage) when the user click the "Add" button positioned next to the...
11
by: Christoph Boget | last post by:
When building a form using Infopath, you can define a repeating section and stick form fields in that section. I'm curious if ASP.NET has a similar control to make it easy to design something...
6
by: =?Utf-8?B?RGFuaWVs?= | last post by:
Hello, I need some help, urgently.. I have got a listbox where the information is retrieved from a database. So for example, if the first row is selected and the button is pressed, I want just...
3
by: bagelman | last post by:
Hi, I want to find repeating words in a long string with Regular Expressions. I tried to write a regular expression but it didn't work. "\b(?<word>\w+)\s+(\k<word>)\b" This RegEx finds...
1
by: redskycorp | last post by:
I have repeating values in my combo box, i do want the values to repeat...any idea how to do that ? The reason is that i am taking the values from my database table "Incomplete" from the "Topic"...
1
by: Swede.Swede | last post by:
Hello! Customer wants a gridview displaying individuals who have taken part in courses. The gridview should be sorted by the name of the participant. If a person has taken part in several...
0
by: Gammazoni | last post by:
Hello, I have a code like that, which has been using by me, but now I need another one, which won't differ a lot, I hope. Please, analize it, I believe that here I'll find somebody with large luggage...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.