Thursday, March 22, 2012

DISTINCT First Name and Last Name for Mail Merge

I'm trying to create a mail merge on my MS SQL database. Many of my owners are entered more than once as they might own multiple properties. I'm trying to write a query where each is only pulled one time and I'm having some trouble. I think I need to use SELECT DISTINCT, but I need to make sure I don't filter out people with the same first name and different last names and vice versa. Thanks!One of my old bosses insisted this could be done using soundex

don't know, but maybe that is an area to start?

http://www.4guysfromrolla.com/webtech/tips/t103101-1.shtml

good luck|||It doesn't need to be that deep.

I thought of another idea. How do I use SELECT DISTINCT to return all rows in my table and only unique address fields?|||I think that a group statement might accomplish this??

as in

select f_name from table group by f_name

I re-read your post...

address validation is a trick...

the address field can be set up many ways, and the street
type designation can also be setup in a whole slew
of different ways...

what does your address field look like (sample data)

thanks
tony|||Soundex is a practically useless algorithm.

You can select distinct First/Last names in a subquery, but then which address would you use if the two records do not agree?

Here is one of the simplest methods:select YourTable.*
from YourTable
inner join --DistinctNames
(select Max(PrimaryKey) as PrimaryKey
from YourTable
group by FirstName,
LastName) DistinctNames
on YourTable.PrimaryKey = DistinctNames.PrimaryKey|||You da' Blindman! Thanks, that's exactly what I needed.|||I hate to post an extension to the question in the same place, but here goes. My owners are listed more than once if they own more than once parcel of land. What I need to do next is continue the merge to each only once, but add up their land acreage amounts and total for each person. Thoughts anyone? Thanks in advance.sql

No comments:

Post a Comment