Showing posts with label addresses. Show all posts
Showing posts with label addresses. Show all posts

Tuesday, March 20, 2012

Comparing 2 tables

Here is my problem:
I have two tables, one table contians used IP addresses and one table contains all of the IP addresses my department has been assigned. What I would like to be able to do is to compare the two tables and return only the IP Addresses that have not been used yet. I have tried such things as the DISTINCT property, but have had no luck. All I get is duplicate data all throughout my query. Any SQL pro's out there ever attempted such a crazy thing? If so, what did you do to solve it? Any advice would be GREATLY appreciated!First of all, force all of your IP addresses into the same format. I'd recommend minimal form (not permitting leading zeros within an octet, a dot between each octet, no leading or trailing blanks). So the "self" address would be formatted as "127.0.0.1" (obviously without the quotation marks) in minimal form. It doesn't really matter which form you use, as long as all of them use the same form.

Then build a table with all of the possible IP addresses within the range that you've been allocated. The easiest way to handle this is usually a nested loop solution to insert the rows. Remember to remove any rows that have been preallocated by network hardware (routers, etc) needed to support the rest of your IP range.

Finally, build a SELECT statement using the list of available IP addresses, and a NOT EXISTS against the IP addresses that you know have been used.

-PatP|||That worked like a charm! Thank you!

Wednesday, March 7, 2012

Compare 2 addresses

Hi,
I hae a DB with a table holding companies, each company has the fields :
name, address, city, state, country and zip.
I have several clients connected to my server application (ASP.Net), and
they sometimes add new companies to the companies table. When they add the
company they don't always take the time to split the different fields of the
company's address and sends it (address, city, state, country and zip) in a
single row. The pattern of the row isn't always the same, sometimes only the
city is added to the address, sometimes only the zip, sometimes none.
I'm trying to make the match between the data the clients send and the data
I already have in my DB in order not to store the same company twice in the
DB.
I've tried using Full-Text Search, I've tried several logical algorithms,
but I can't make an automatic solution to this problem.
Please add any idea you may have on how I can make this comparission as
automatic as possible.
ThanksYou're best bet would be to scrub the data when it's entered, i.e.--change
the app to prevent the concatenated addresses. The only alternative I can
think of would be to split the incoming data into tokens like a compiler, an
d
then compare the token pattern against a syntax graph to categorize the data
.
It might be easier to reverse the graph, in other words, work backward: a
zip code usually has a pattern of either ##### or #####-####, unless you're
in Canada. The state or province usually preceeds the zip code, the city
preceeds the state or province, etc.
"YN" wrote:

> Hi,
> I hae a DB with a table holding companies, each company has the fields :
> name, address, city, state, country and zip.
> I have several clients connected to my server application (ASP.Net), and
> they sometimes add new companies to the companies table. When they add the
> company they don't always take the time to split the different fields of t
he
> company's address and sends it (address, city, state, country and zip) in
a
> single row. The pattern of the row isn't always the same, sometimes only t
he
> city is added to the address, sometimes only the zip, sometimes none.
> I'm trying to make the match between the data the clients send and the dat
a
> I already have in my DB in order not to store the same company twice in th
e
> DB.
> I've tried using Full-Text Search, I've tried several logical algorithms,
> but I can't make an automatic solution to this problem.
> Please add any idea you may have on how I can make this comparission as
> automatic as possible.
> Thanks|||Thanks for your reply Brian,
I can't force the users to split the address to separate fields. I usually
don't have a problem with identifying the country and state, however this is
not the case when dealing cities and addresses.
My current algorithm is (for a1 (=address1), a2 (=address2), c1 (=city1), c2
(=city2)
1. Remove all non relevant chars (non literal or numeric chars) from all.
Remove "non relevant words" like "street","road","st." etc from addresses.
2. Check if c1 is null. If so check if c2 exists in a1 and if so remove it
from the address and set c1 = c2
3. The other way around (c2 and a1)
4. tokenize the results by spaces and try to find matches between them
(since sometimes the structure is streen name followed by building number an
d
sometimes its the other waty around)
Do you perhaps have a better suggestion ?
"Brian Selzer" wrote:
> You're best bet would be to scrub the data when it's entered, i.e.--change
> the app to prevent the concatenated addresses. The only alternative I can
> think of would be to split the incoming data into tokens like a compiler,
and
> then compare the token pattern against a syntax graph to categorize the da
ta.
> It might be easier to reverse the graph, in other words, work backward: a
> zip code usually has a pattern of either ##### or #####-####, unless you'r
e
> in Canada. The state or province usually preceeds the zip code, the city
> preceeds the state or province, etc.
> "YN" wrote:
>|||Thanks for your reply Brian,
I can't force the users to split the address to separate fields. I usually
don't have a problem with identifying the country and state, however this is
not the case when dealing cities and addresses.
My current algorithm is (for a1 (=address1), a2 (=address2), c1 (=city1), c2
(=city2)
1. Remove all non relevant chars (non literal or numeric chars) from all.
Remove "non relevant words" like "street","road","st." etc from addresses.
2. Check if c1 is null. If so check if c2 exists in a1 and if so remove it
from the address and set c1 = c2
3. The other way around (c2 and a1)
4. tokenize the results by spaces and try to find matches between them
(since sometimes the structure is streen name followed by building number an
d
sometimes its the other waty around)
Do you perhaps have a better suggestion ?
"Brian Selzer" wrote:
> You're best bet would be to scrub the data when it's entered, i.e.--change
> the app to prevent the concatenated addresses. The only alternative I can
> think of would be to split the incoming data into tokens like a compiler,
and
> then compare the token pattern against a syntax graph to categorize the da
ta.
> It might be easier to reverse the graph, in other words, work backward: a
> zip code usually has a pattern of either ##### or #####-####, unless you'r
e
> in Canada. The state or province usually preceeds the zip code, the city
> preceeds the state or province, etc.
> "YN" wrote:
>|||Look up the tools that Mellisa Data sells for cleaning up addresses.|||YN
If i understood you may want to write a trigger or better stored procedure
to catch then INSERT a new company and check all data
declare @.address VARCHAR(100)
IF EXISTS (SELECT * FROM Table WHERE address =@.address AND company=@.company
AND .....)
PRINT 'You are trying to insert a duplicate'
"YN" <YN@.discussions.microsoft.com> wrote in message
news:F8C33439-18BB-4183-98DD-BDB2F244BF0B@.microsoft.com...
> Hi,
> I hae a DB with a table holding companies, each company has the fields :
> name, address, city, state, country and zip.
> I have several clients connected to my server application (ASP.Net), and
> they sometimes add new companies to the companies table. When they add the
> company they don't always take the time to split the different fields of
the
> company's address and sends it (address, city, state, country and zip) in
a
> single row. The pattern of the row isn't always the same, sometimes only
the
> city is added to the address, sometimes only the zip, sometimes none.
> I'm trying to make the match between the data the clients send and the
data
> I already have in my DB in order not to store the same company twice in
the
> DB.
> I've tried using Full-Text Search, I've tried several logical algorithms,
> but I can't make an automatic solution to this problem.
> Please add any idea you may have on how I can make this comparission as
> automatic as possible.
> Thanks

Company with Address Question

I have a database that allows a client to have multiple addresses, could be a home, business, vacation, etc... I'm trying to deside if I should put the Company Name and Title fileds in the tblClientAddresses table or keep it with the tblClient table. We do mailings to clients and if the mail is going to a home address the company and title should be excluded. If I put them in the tblClients table I really have no way of knowing if we are mailing to a home or a company. If i put the company and title with the address it makes sence that this would solve the issue.

Looking for any thoughts or suggestions?

Thank you,Standard normalization would say if there are multiple addresses per client, put it in a separate table. The only time I would recommend against this is for performance reasons, but I'm guessing you don't have any performance problems yet.|||The Company Name and Title fields belong in tblClient.

You could do something like this to make them blank if the address is a Home address:


SELECT
CASE
WHEN A.type = 'Home' THEN ''
ELSE C.Name
END AS Name,
CASE
WHEN A.type = 'Home' THEN ''
ELSE C.Title
END AS Title,
A.Address1,
A.Address2,
A.City,
A.State,
A.ZIP
FROM
tblClient C
INNER JOIN
tblClientAddress A ON C.ClientID = A.ClientID

As the OP said, though, sometimes you give up correct normalization for performance -- especially if the data is static and the tables are extremely large.

Terri

Friday, February 10, 2012

comma delimited list

Hello,
I have created a small query that will output a list of email addresses that
are separated by commas. I plan to copy and paste the list into a email
invite field (send to: field for an email app). But what is happening is tha
t
only one address appears in the field when I paste because of the added
spaces between the names, example currently outputs like:
blahblah@.blah.com,
blahblah@.blah.com,
blahblah@.blah.com
What I need is it to output like this:
blahblah@.blah.com,blahblah@.blah.com,blahblah@.blah.com
Here is the small query that I am using to extract the emails.
SELECT RTRIM(LTRIM(EMAIL_ADDRESS)) + ',' AS [Name]
FROM evPRUclinicala
WHERE CREATE_DATE BETWEEN '4/1/06' AND '4/30/06'
AND EMAIL_ADDRESS IS NOT NULL
Any help would be appreciated and thanks in advance.
Message posted via http://www.webservertalk.comIn general, a recommended approach is to extract the resultset outside the
server and massage the data to appropriate display format using some client.
Regarding the alterantives for doing it at the server, you can check out the
following links:
( For SQL 2005 only )
http://groups.google.com/group/micr...br />
9b9b968a
( For SQL 2000 & 2005 )
http://groups.google.com/group/micr...br />
6dd9e73e
Anith|||Anith Sen wrote:
>In general, a recommended approach is to extract the resultset outside the
>server and massage the data to appropriate display format using some client
.
>Regarding the alterantives for doing it at the server, you can check out th
e
>following links:
>( For SQL 2005 only )
>http://groups.google.com/group/micr...r />
a9b9b968a
>( For SQL 2000 & 2005 )
>http://groups.google.com/group/micr...r />
66dd9e73e
>
Thanks for the direction, but I am still have some problems. I elected to us
e
the cursor version of your solution: see below
DECLARE @.temptable TABLE ( list VARCHAR( 8000 ) )
SET NOCOUNT ON
DECLARE @.PRUemail VARCHAR( 1000 ), @.emailNext VARCHAR (100)
DECLARE c CURSOR FOR
SELECT EMAIL_ADDRESS
FROM evPRUclinicala
ORDER BY EMAIL_ADDRESS
OPEN c
FETCH NEXT FROM c INTO @.emailNext
SET @.PRUemail = @.emailNext
WHILE @.@.FETCH_STATUS = 0 BEGIN
IF @.emailNext > @.PRUemail BEGIN
INSERT @.temptable SELECT @.PRUemail
SELECT @.PRUemail = @.emailNext
END ELSE
SET @.PRUemail = COALESCE( @.PRUemail + ',', SPACE( 0 ) ) +
@.emailNext
FETCH NEXT FROM c INTO @.emailNext
END
INSERT @.temptable SELECT @.PRUemail
CLOSE c
DEALLOCATE c
SET NOCOUNT OFF
SELECT * FROM @.temptable
But I am still getting a vertical list with no commas. Can you tell me what
I
am doing wrong? Thanks
Message posted via http://www.webservertalk.com|||>> I elected to use the cursor version of your solution:
Why? It is a bad choice to begin with.
I have no idea how the table evPRUclinicala is structured or what the nature
of the data is. Can you post your table DDLs & a few sample data? For
details, refer to: www.aspfaq.com/5006
Anith|||"Jay via webservertalk.com" <u7124@.uwe> wrote in message
news:601bd1f4c21b5@.uwe...
>.
> Can you tell me what I am doing wrong?
>.
Yeah, your not using Rac :)
www.rac4sql.net/onlinehelp.asp?topic=236|||Anith Sen wrote:
>Why? It is a bad choice to begin with.
>
>I have no idea how the table evPRUclinicala is structured or what the natur
e
>of the data is. Can you post your table DDLs & a few sample data? For
>details, refer to: www.aspfaq.com/5006
>
What would have been a better choice? If I should use a different method tha
n
I would appreciate your advise here. If not I will get you the DDLs.
Message posted via webservertalk.com
http://www.webservertalk.com/Uwe/Forum...amming/200605/1|||Cursors are generally performance hogs. In most cases, it is wiser to
utilize a set based solution in SQL where a set of rows are manipulated as a
whole rather than doing it one row at a time.
As a long term solution, consider returning the resultset to the client and
manipulate the data using a client application program -- this allows the
stored procedure to be sufficiently generic, eliminates the need to use
server's processing power for string manipulations & loop-based constructs
and leverages the string functionalities of the client language, which in
most cases are more versatile than t-SQL.
If you are convinced to use the server for such stuff, consider the table
valued UDF approach which might be better performing for medium sized
datasets. For SQL 2005, the XML kludge might be faster, though we do not
have much useful benchmarks with this approach.
Alternatively, for large volume transactions of this nature, consider using
3rd party tool's like RAC mentioned in Steve's post.
Anith|||Anith Sen wrote:
>Why? It is a bad choice to begin with.
>
>I have no idea how the table evPRUclinicala is structured or what the natur
e
>of the data is. Can you post your table DDLs & a few sample data? For
>details, refer to: www.aspfaq.com/5006
>
Ok I will look at the other solutions rather than the one chosen. Thanks
Message posted via webservertalk.com
http://www.webservertalk.com/Uwe/Forum...amming/200605/1

comma deliminited coloumn

I have two tables. One table (Table 1) has a column containing comma
delaminated email addresses. The other table (Table 2) has a column
with just one email address in it. I need to perform a query that
joins the comma delaminated table (Table 1) to Table 2, when the single
email address in Table 2, is contained in the list of email addresses
in (Table 1).

I hope this isn't too cryptic, and I know comma delaminated lists are
bad, but I can't do anything about that.

I need a select statement that can perform this task. Anyone have any
suggestions?--BEGIN PGP SIGNED MESSAGE--
Hash: SHA1

Set the WHERE clause like this:

WHERE table1.columnA like '%' + table2.columnA + '%'

BTW, it's "delimited" not "delaminated." Delaminated means to remove
the lamination (thin layers of some material) from a surface.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

--BEGIN PGP SIGNATURE--
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRAYMHoechKqOuFEgEQLfUgCgiFts2PFVLGIgVtIozCwnTc AinqsAoOIg
GOmdcAyO5uy641wMCQWwt4Sj
=3bUQ
--END PGP SIGNATURE--

cholmqui@.gmail.com wrote:
> I have two tables. One table (Table 1) has a column containing comma
> delaminated email addresses. The other table (Table 2) has a column
> with just one email address in it. I need to perform a query that
> joins the comma delaminated table (Table 1) to Table 2, when the single
> email address in Table 2, is contained in the list of email addresses
> in (Table 1).
> I hope this isn't too cryptic, and I know comma delaminated lists are
> bad, but I can't do anything about that.
> I need a select statement that can perform this task. Anyone have any
> suggestions?|||Thank you for the reply.

still doesn't work...

Sorry about the lamination, I kinda flew through the spell checker|||(cholmqui@.gmail.com) writes:
> Thank you for the reply.
> still doesn't work...

MGFosters looks good to me at a glance. Maybe you could be more specfic
to what does not work? Even better, provide CREATE TABLE statments and
INSERT statements with sample data. Then you can get a tested solution.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||This design seems to suck. You need some procedural routines to scrub
data, You need to look at Melisa data's website.