Showing posts with label email. Show all posts
Showing posts with label email. Show all posts

Wednesday, March 21, 2012

Need assistance with Duplicate Select Statment

Any help would be appreciated here. My question is two part:

1.) Select duplicates that match any of a number of columns for example...

The email is the same OR

The homephone is the same OR

The mobilephone is the same OR

The address1 is the same

The uniqueID is ConsIntID

My Select Statement: (Which does not work)

SELECT CONSINTID, FIRSTNAME, LASTNAME, EMAIL1, ADDRESS1, HOMEPHONE, MOBILEPHONE, CREATEDATE, USERIDS

FROM CONSULTANTS

WHERE CONSINTID IN (SELECT CONSINTID

FROM CONSULTANTS

HAVING COUNT(HOMEPHONE) > 1 OR COUNT(MOBILEPHONE) >1 OR etc.... )

-

Once the Select Duplicates Statement is corrected I will insert those into a ConsultantsDupe Table

The Second Question is: If I have more then one duplicate my stored_procedure fails

Here is my cursor and logic. The problem is getting multiple results in the subquery and I don't know the best way to correct this.

DECLARE DUPES CURSOR FOR

SELECT CONSINTID, FIRSTNAME, LASTNAME, EMAIL1, ADDRESS1, HOMEPHONE, MOBILEPHONE, CREATEDATE, USERIDS

FROM CONSULTANTS_DUPS

ORDER BY CREATEDATE DESC

OPEN DUPES

FETCH NEXT FROM DUPES

INTO @.CONSINTID, @.FIRSTNAME, @.LASTNAME, @.EMAIL1, @.ADDRESS1, @.HOMEPHONE, @.MOBILEPHONE, @.CREATEdATE, @.USERIDS

WHILE @.@.FETCH_STATUS = 0

BEGIN

SET @.FOUNDCONSINTID = (SELECT DISTINCT CONSINTID FROM CONSULTANTS_DUPS

WHERE CONSINTID <> @.CONSINTID AND HOMEPHONE = @.HOMEPHONE "NEED TO ADD COMPARISON FOR MOBILEPHONE, EMAIL ADDRESS HERE") <== This can provide more then one result which messes me up.

I'll take a couple shots at this. Hopefully somebody can post something even better. You'll have to forgive me. Without any sample tables I had to "shoot from the hip" and write it without any syntax checking.

SELECT * FROM Consultants C

WHERE EXISTS (SELECT * FROM Consultants CPhone

WHERE (C.HomePhone = CPhone.HomePhone

OR C.HomePhone = CPhone.CellPhone

OR C.CellPhone = CPhone.HomePhone

OR C.CellPhone = CPhone.CellPhone)

AND C.CONSINTID <> CPhone.CONSINTID

)

OR EXISTS (SELECT * FROM Consultants CEmail

WHERE C.EMAIL1 = CEmail.EMAIL1

AND C.CONSINTID <> EMAIL1.CONSINTID)

OR EXISTS ...

Here's another shot:

SELECT * FROM Consultants

WHERE HomePhone IN (SELECT HomePhone

FROM Consultants

WHERE HomePhone IS NOT NULL

GROUP BY HomePhone

HAVING COUNT(*) > 1)

OR CellPhone IN (SELECT CellPhone

FROM Consultants

WHERE CellPhone IS NOT NULL

GROUP BY CellPhone

HAVING COUNT(*) > 1)

OR Email1 IN (SELECT Email1

FROM Consultants

WHERE Email1 IS NOT NULL

GROUP BY Email1

HAVING COUNT(*) > 1)

This method suffers from the fact that you can't check HomePhone and CellPhone at the same time (with UNION ALL) because of a contact has the same phone number listed as home and cell then it could show up as a duplicate.

Here's where you might take the previous query as a natural transition to cross-check home phone against cell phone:

SELECT * FROM Consultants C

WHERE HomePhone IN (SELECT HomePhone

FROM (SELECT CONSINTID, HomePhone

FROM Consultants UNION

SELECT CONSINTID, CellPhone

FROM Consultants) SubQ

WHERE HomePhone IS NOT NULL

GROUP BY HomePhone

HAVING COUNT(*) > 1)

OR CellPhone IN (SELECT HomePhone

FROM (SELECT CONSINTID, HomePhone

FROM Consultants UNION

SELECT CONSINTID, CellPhone

FROM Consultants) SubQ

WHERE HomePhone IS NOT NULL

GROUP BY HomePhone

HAVING COUNT(*) > 1)

OR Email1 IN (SELECT Email1

FROM Consultants

WHERE Email1 IS NOT NULL

GROUP BY Email1

HAVING COUNT(*) > 1)

You may also be better off with multiple SELECT statements as it's hard to tell the cause of your duplicate in a query like this. Keep in mind that all of these queries are very read-intensive as you're dealing with multiple scans across your table. You may benefit, instead, by placing your duplicates in a temporary table (or table variable) and then querying against the temporary table.

|||something like this:

select *
from consultants
where consintid in
(select consintid
from consultants
group by email
having count(*)>1
union all
select consintid

from consultants

group by homephone

having count(*)>1

union all
select consintid

from consultants

group by cellphone

having count(*)>1

union all
select consintid

from consultants

group by address1

having count(*)>1
)|||

Jared,

Yours worked! This gives me what I need for the duplicate temp table and the assistance is greatly appreciated.

Any feedback on the second portion?

Friday, March 9, 2012

Need advice how to write a program to receive an image via email and put it into the SQL S

Hello,
I am trying to find a way to write a program to do the following:
Receive an image via email, retrieve that image and put it into a database.
Could you please give me an advice where to start or point me into the right
direction? Is there an ASP component somewhere that would do the trick?
P.S. I have my own Windows 2003 server and SQL Server 2000, and can install
anything on my server if I need to.
Thank you,
Robert ZolnarHi Vanessa
If you can send the image as an attachment xp_readmail can save this to disc
where it can then be loaded in to the database. For SQL Mail you will need a
MAPI client e.g. Outlook 2000 installed on the server. Check out
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnovba01/html/SQLServerE-mail.asp
and Books online for more. Once the image has been materialised you than
then use something like the Bii sample program to load it
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/samples/samples_2isp.asp
If you want to do away with the Email you could use upload the image file
into a location (share) that is accessable by your SQL Server see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/samples/samples_2isp.asp
This link also discusses the pros and cons of storing images in the database
John
"Vanessa Lee" <van77788@.yahoo.com> wrote in message
news:roKdnfLGWt-zymXeRVn-sw@.comcast.com...
> Hello,
> I am trying to find a way to write a program to do the following:
> Receive an image via email, retrieve that image and put it into a
> database.
> Could you please give me an advice where to start or point me into the
> right
> direction? Is there an ASP component somewhere that would do the trick?
> P.S. I have my own Windows 2003 server and SQL Server 2000, and can
> install
> anything on my server if I need to.
> Thank you,
> Robert Zolnar
>|||Hello John,
Thank you for your reply. Now that I know about MAPI as you mentioned, I
wonder if there is a way to avoid using SQL server at all and saving the
image to a file with a specific filename for a later retrieval.
Here is how I think it would work:
(1) Receive an image in email attachment.
(2) Retrieve the image from that attachment.
(3) Change the name of the image file into what was written in the Subject
of that email.
(4) Save the renamed image file into a specific folder.
(5) Delete the received email
Do you know about any other components or programs somewhere on the net
already written preferably in VBScript that it might be helpful for me to
look at?
Thank you.
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:O6LWOqVNGHA.720@.TK2MSFTNGP14.phx.gbl...
> Hi Vanessa
> If you can send the image as an attachment xp_readmail can save this to
disc
> where it can then be loaded in to the database. For SQL Mail you will need
a
> MAPI client e.g. Outlook 2000 installed on the server. Check out
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnovba01/html/SQLServerE-mail.asp
> and Books online for more. Once the image has been materialised you than
> then use something like the Bii sample program to load it
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/samples/samples_2isp.asp
> If you want to do away with the Email you could use upload the image file
> into a location (share) that is accessable by your SQL Server see
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/samples/samples_2isp.asp
> This link also discusses the pros and cons of storing images in the
database
> John
>
> "Vanessa Lee" <van77788@.yahoo.com> wrote in message
> news:roKdnfLGWt-zymXeRVn-sw@.comcast.com...
> > Hello,
> >
> > I am trying to find a way to write a program to do the following:
> >
> > Receive an image via email, retrieve that image and put it into a
> > database.
> >
> > Could you please give me an advice where to start or point me into the
> > right
> > direction? Is there an ASP component somewhere that would do the trick?
> >
> > P.S. I have my own Windows 2003 server and SQL Server 2000, and can
> > install
> > anything on my server if I need to.
> >
> > Thank you,
> > Robert Zolnar
> >
> >
>|||Hi
What you are wanting to do should certainly be possible, although I have
never used it with VBScript. See
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/exchanchor/htms/msexchsvr_mapi.asp for the SDK although the example are mainly in C/C++
John
"Vanessa Lee" wrote:
> Hello John,
> Thank you for your reply. Now that I know about MAPI as you mentioned, I
> wonder if there is a way to avoid using SQL server at all and saving the
> image to a file with a specific filename for a later retrieval.
> Here is how I think it would work:
> (1) Receive an image in email attachment.
> (2) Retrieve the image from that attachment.
> (3) Change the name of the image file into what was written in the Subject
> of that email.
> (4) Save the renamed image file into a specific folder.
> (5) Delete the received email
> Do you know about any other components or programs somewhere on the net
> already written preferably in VBScript that it might be helpful for me to
> look at?
> Thank you.
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:O6LWOqVNGHA.720@.TK2MSFTNGP14.phx.gbl...
> > Hi Vanessa
> >
> > If you can send the image as an attachment xp_readmail can save this to
> disc
> > where it can then be loaded in to the database. For SQL Mail you will need
> a
> > MAPI client e.g. Outlook 2000 installed on the server. Check out
> >
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnovba01/html/SQLServerE-mail.asp
> > and Books online for more. Once the image has been materialised you than
> > then use something like the Bii sample program to load it
> >
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/samples/samples_2isp.asp
> >
> > If you want to do away with the Email you could use upload the image file
> > into a location (share) that is accessable by your SQL Server see
> >
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/samples/samples_2isp.asp
> > This link also discusses the pros and cons of storing images in the
> database
> >
> > John
> >
> >
> > "Vanessa Lee" <van77788@.yahoo.com> wrote in message
> > news:roKdnfLGWt-zymXeRVn-sw@.comcast.com...
> > > Hello,
> > >
> > > I am trying to find a way to write a program to do the following:
> > >
> > > Receive an image via email, retrieve that image and put it into a
> > > database.
> > >
> > > Could you please give me an advice where to start or point me into the
> > > right
> > > direction? Is there an ASP component somewhere that would do the trick?
> > >
> > > P.S. I have my own Windows 2003 server and SQL Server 2000, and can
> > > install
> > > anything on my server if I need to.
> > >
> > > Thank you,
> > > Robert Zolnar
> > >
> > >
> >
> >
>
>