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 8910165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:37:07+00:00 2026-06-15T03:37:07+00:00

This query currently takes about 30 seconds to run. I’d like some help speeding

  • 0

This query currently takes about 30 seconds to run.

I’d like some help speeding it up, but don’t know how to go about doing it. Any help would be fantastic. Please Note: I’m unable to make any actual changes to the database or it’s design at this time.

SELECT top 1 v.[address], v.[address2], v.[city], v.[state_prov_id],v.[postcode],
        v.[first_name], v.[last_name], v.[client_specific_id], v.[name], v.phone,
        v.Location_id, v.Contact_id, v.Event_ID, v.client_id, v.program_id,
        v.source_code_id, v.file_source_code_id, v.URL, v.ScriptFrame,
        v.calldatemark, v.NumCallMark + 1 as Numcallmark,
        v.NumCallMarkDay + 1 as NumCallMarkDay,
        v.NumCallMarkWeek + 1 as NumCallMarkWeek, v.autoaudio,
        v.autohumantext, v.automachinetext 
   FROM vw_locationcontactdialer v 
  WHERE v.program_id = 10001565
    and v.numcallmark < 3 
    and (dateadd(hh,72,v.calldatemark) < getdate()
        or v.calldatemark = '01/01/1900' or v.calldatemark is null) 
    and  source_code_id = 10015311 
    and v.contact_id not in ( select contact_ID from CALL_HISTORY with (NOLOCK) 
                               where program_ID = 10001565 
                                 and result_id not in ('8','U','N')
                               group by contact_ID)
  order by calldatemark

I was given a tip to try and do a JOIN, but I’m unsure how I would accomplish this. I’m not sure how to do a JOIN and make sure that all contact_id’s not in the subquery is accomplished.

I came up with this:

SELECT TOP 1 v.[address], v.[address2], v.[city], v.[state_prov_id],v.[postcode],
            v.[first_name], v.[last_name], v.[client_specific_id], v.[name],
            v.phone, v.Location_id, v.Contact_id, v.Event_ID, v.client_id,
            v.program_id, v.source_code_id, v.file_source_code_id, v.URL,
            v.ScriptFrame, v.calldatemark,
            v.NumCallMark + 1 as Numcallmark,
            v.NumCallMarkDay + 1 as NumCallMarkDay,
            v.NumCallMarkWeek + 1 as NumCallMarkWeek, v.autoaudio,
            v.autohumantext, v.automachinetext 
  from vw_locationcontactdialer v 
  JOIN CALL_HISTORY ch on v.Contact_ID = ch.contact_ID
 where v.Program_ID = 10001565
   and v.NumCallMark < 3
   and (DATEADD(hh,72,v.calldatemark) < GETDATE() 
        or v.CallDateMark = '01/01/1900' or v.CallDateMark is null)
   and v.Source_Code_ID = 10015311
   and ch.result_ID not in ('8','U','N')
 group by ch.contact_id
 order by v.CallDateMark

but it’s not working because of this error, which I don’t fully understand: Msg 8120, Level 16, State 1, Line 1
Column ‘vw_locationcontactdialer.address’ is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

Any help would be awesome.

  • 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-06-15T03:37:10+00:00Added an answer on June 15, 2026 at 3:37 am

    You can turn this into a join as follows:

    from vw_locationcontactdialer v left outer join
         (select contact_ID
          from CALL_HISTORY with (NOLOCK) 
          where program_ID = 10001565 and 
                result_id not in ('8','U','N')
          group by contact_ID
         ) ch
         on v.contact_id = vh.contact_id
    where . . .
          ch.contact_id is null
    order by calldatemark
    

    (Apologies, I get an error if I try to post the entire query.)

    To make this work better, though, you probably want to go back to your original query and use a correlated subquery:

    where
          not exists (select 1
                      from CALL_HISTORY ch with (NOLOCK) 
                      where program_ID = 10001565 and 
                            result_id not in ('8','U','N') and
                            ch.contact_id = v.contact_id
                     )
    

    It woudl then help if you had an index on CALL_HISTORY.Contact_Id. Even better, a multipart index on Call_History encompassing contact_id, result_id, and program_id.

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

Sidebar

Related Questions

Currently I'm running a MySQL query like this $query = SELECT t1.id AS 'post_id',
I currently have a query that looks like this: SELECT NON EMPTY ([Measures].[TOTAL]) ON
I'm currently trying to run a LINQ query over a MS SQL database. This
How to I format a query string so it looks like this search?q=power+tools currently
This is related to my previous thread: SQL Query takes about 10 - 20
The problem: My company currently has a query that takes roughly 3 seconds to
Looking to do a bit of refactoring... Using NHibernate I have this query currently
I'm currently doing this query to find the guy who makes the most calls:
For this query: $sql='select col from table where other_col=?'; I am currently getting the
Currently, I am using this query, which does a pretty good job of finding

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.