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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:44:57+00:00 2026-06-12T04:44:57+00:00

The below code is taking too long to run. I know it is the

  • 0

The below code is taking too long to run. I know it is the code:

case when (select (concat(alias,' - ',firm))
        from publiccontact where replace(replace(replace(replace(businessnumber,'+44 (','0'),') ',''),'+44','0'),')','') =  tax.callerid1 and businessnumber <> ''
            limit 1
            ) is not null then
            (select (concat(alias,' - ',firm))
        from publiccontact where replace(replace(replace(replace(businessnumber,'+44 (','0'),') ',''),'+44','0'),')','') =  tax.callerid1 and businessnumber <> ''
            limit 1
            ) else (select (concat(alias,' - ',firm))
        from publiccontact where replace(replace(replace(replace(mobilenumber,'+44 (','0'),') ',''),'+44','0'),')','') =  tax.callerid1 and mobilenumber <> ''
            limit 1
            )
    end as callername,

Could I make my case and sub selects more efficient? My code works, but is definitely not efficient.

select  date(instime) as date,
    Pkey as ID,
    subscriber as user,
    SUBSCRIBERNAME as userName,
    case when (select (concat(alias,' - ',firm))
        from publiccontact where replace(replace(replace(replace(businessnumber,'+44 (','0'),') ',''),'+44','0'),')','') =  tax.callerid1 and businessnumber <> ''
            limit 1
            ) is not null then
            (select (concat(alias,' - ',firm))
        from publiccontact where replace(replace(replace(replace(businessnumber,'+44 (','0'),') ',''),'+44','0'),')','') =  tax.callerid1 and businessnumber <> ''
            limit 1
            ) else (select (concat(alias,' - ',firm))
        from publiccontact where replace(replace(replace(replace(mobilenumber,'+44 (','0'),') ',''),'+44','0'),')','') =  tax.callerid1 and mobilenumber <> ''
            limit 1
            )
    end as callername,
    (select (concat(alias,' - ',firm))
        from publiccontact where replace(replace(replace(replace(businessnumber,'+44 (','0'),') ',''),'+44','0'),')','') =  tax.destinationnumber1 and businessnumber <> ''
            limit 1
            )
    as destinationname,
    case when direction = 1 then 'incoming' else 'outgoing' end as direction,
    case when CALLDESTINATION = 1 then 'public' else 'private' end as destination,
    startdate as StartDate,
    starttime as StartTime,
    duration as DuractionSec,
    TIMETOANSWER as TimeAnswerSec,
    TAXCHARGES as Charges,
    coalesce(callerid1,callerid2,'') as CallerID,
    coalesce(destinationnumber1,destinationnumber2,'') as DestinationNumber,
    ORIGINSUBSCRIBER as UserNumber,
    completed as CallCompleted,
    coalesce(case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 2123 then 'Incoming Call Transfered External' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 1132 then 'Incoming Call Transfered External' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 1131 then 'Incoming Call Transfered Interal' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 1132 then 'Incoming Call Transfered Interal' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 1233 then 'AMC Call Answered' else null end, 
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 2122 then 'Incoming DDI call answered by GSM' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 1232 then 'AMCOutgoing' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 2111 then 'OutgoingCallTransferedInternally' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 2121 then 'OutgoingCallTransferedInternally' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 2123 then 'OutgoingCallTransferedtoExternal' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 1252 then 'IncomingCallPrivateNetworkCallShouldBeIgnored' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 1143 then 'IncACDCallUnaws' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 1142 then 'IncACDCallAnswered' else null end,'') as type

from taxticketitem tax;

Kind regards

  • 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-12T04:44:59+00:00Added an answer on June 12, 2026 at 4:44 am

    MySQL 5.0 IFNULL

    Using an IFNULL expression would cut out an additional select in the case when the first select is not null…

    ifnull (
      (select (concat(alias,' - ',firm))
      from publiccontact where replace(replace(replace(replace(businessnumber,'+44 (','0'),') ',''),'+44','0'),')','') =  tax.callerid1 and businessnumber <> ''
      limit 1),   
      (select (concat(alias,' - ',firm))
      from publiccontact where replace(replace(replace(replace(mobilenumber,'+44 (','0'),') ',''),'+44','0'),')','') =  tax.callerid1 and mobilenumber <> ''
      limit 1)
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When i'm displaying image from url with using below code, application is taking too
The below given code of is taking infinitely long time to load in a
below code is my databasehandler class i got it from a tutorial. Beside that
HI: Below code is from RequestFactoryEditorDriver: /** * Returns a new array containing the
This is my below code which is drawing a Circle within Circle and taking
In below code...the tag is $mname1 is right now, taking only three value APRIL,
I am taking the screen shot on .mm file i used the below code
I am using below code to get the Audio from library for triming here
After taking help from StackOverflow, I found the solution that I have implemented below.
Below code not work, but it's work fine for jsf1.2. Now the framework is

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.