Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6081443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:10:34+00:00 2026-05-23T11:10:34+00:00

I have two tables: Table 1: CustomerEmails: CREATE TABLE [dbo].[CustomerEmails]( [id] [int] IDENTITY(1,1) NOT

  • 0

I have two tables:

Table 1: CustomerEmails:

CREATE TABLE [dbo].[CustomerEmails](
    [id]            [int] IDENTITY(1,1) NOT NULL,
    [datecreated]   [datetime] NULL,
    [UID]           [nvarchar](250) NULL,
    [From]          [nvarchar](100) NULL,
    [To]            [nvarchar](100) NULL,
    [Subject]       [nvarchar](max) NULL,
    [Body]          [nvarchar](max) NULL,
    [Dated]         [datetime] NULL,
 CONSTRAINT [PK_CustomerEmails] PRIMARY KEY CLUSTERED 
(
    [id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
)

Table 2: CustomerEmailIds:

CREATE TABLE [dbo].[CustomerEmailIds](
    [Email] [varchar](200) NULL
) ON [PRIMARY]

You may be thinking that why i am not using the EmailId in table CustomerEmails instead of using the emails itself? what i mean is that i can add a column EmailId (INT) to the table CustomerEmailIds & then i can refer that column instead of CustomerEmails.From & CustomerEmails.To?? Guys the issue is the table CustomerEmails is used by some other application & that application just keeps the track of emails sent/received through OutLook. The table CustomerEmailIds have customer emails & these emails come into system from the application i am working on.

So the Table CustomerEmails have 7,00,000+ records while table CustomerEmailIds have 1,00,000+ records.

I need to find out the emails from table CustomerEmails, based on the emails in CustomerEmailIds table.

The query i am using is:

SELECT  
        e.*
FROM    CustomerEmails e 
WHERE   EXISTS 
        (
            SELECT  Email 
            FROM    CustomerEmailIds c 
            WHERE   ( ISNULL(e.[From],'') + '/' + ISNULL(e.[To],'') ) LIKE  '%'+c.Email+'%' 
        )

Some facts:
1- I am using SQL Server 2008
2- Sorry guys, i forgot to mention that the CustomerEmails.**To** can contains multiple comma separated emails like: email1@yahho.com,email2@yahho.com,email3@yahho.com
3- Because of the fact2 the c.Cs3Emails+'%' OR to= c.Cs3Emails will not list the desired results that's why i am using '%'+c.Cs3Emails+'%'

Latest Findings:
Guys the above query return wrong results….. & i don’t know why??

But below query works fine:

SELECT  
    e.*
FROM    CustomerEmails e 
WHERE   (ISNULL(e.[From],'') + '/' + ISNULL(e.[To],'')) LIKE  '%email1@gmail.com%' 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:10:35+00:00Added an answer on May 23, 2026 at 11:10 am

    Well guys first look at the query which is returning the wrong results:

    SELECT  
            e.*
    FROM    CustomerEmails e 
    WHERE   EXISTS 
            (
                SELECT  Email 
                FROM    CustomerEmailIds c 
                WHERE   ( ISNULL(e.[From],'') + '/' + ISNULL(e.[To],'') ) LIKE  '%'+c.Email+'%' 
            )
    

    There is no issue in this query, the issue is that some of the emails in CustomerEmailIds table are invalid emails which are (‘.’,’@’,’0′,’-‘) & that’s why the query is returning all the CustomerEmails where these invalid emails exists.

    Thanks to Kev Riley! the persons who helped me find out the cause of this issue here!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: CREATE TABLE [dbo].[Task]( [SysTask] [int] IDENTITY(1,1) NOT NULL, [TaskStatus] [int]
I have two tables: CREATE TABLE InmarsatZenith.dbo.ClientJob (JobRef int PRIMARY KEY NOT NULL, IntRef
I have two tables: CREATE TABLE [dbo].[Context] ( [Identity] int IDENTITY (1, 1) NOT
I have two tables: CREATE TABLE 'sales_sheet' ( `_id` int(11) NOT NULL AUTO_INCREMENT, `_typed_by`
I have two tables: CREATE TABLE dbo.country ( cntry_id VARCHAR(2) NOT NULL, name VARCHAR(50)
i have two tables: CREATE TABLE public.auctions ( id VARCHAR(255) NOT NULL, auction_value_key VARCHAR(255)
i have two tables CREATE TABLE IF NOT EXISTS `user` ( `user_id` int(20) NOT
I have two tables: CREATE TABLE IF NOT EXISTS `comments` ( `id` int(11) NOT
I have two tables: CREATE TABLE Event_details( event_no INTEGER AUTOINCREMENT NOT NULL, no_players INTEGER
I have two tables: CREATE TABLE items ( root_id integer NOT NULL, id serial

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.