Sqlserver time out when use multiple leftjoin in searcing

Can anyone explain what reason cause follow #2,#3,#4,#5, i'm confusing for this problem in whole afternoon . thank you very much.
you can copy the follow small example to see the timeout issue , if your pc is too quick, haven't yet see timeout issue in 24 tempBookAddress. just add more left join for TempBookAddress, then the the issue will show up.
1.Create three temptables
create Table #TempBookAddress
   BookID int,
   AddressTypeID nvarchar(1)
Create Table #TempBook1
(BookID int)
insert into #TempBook1(BookID) values(1930)
insert into #TempBook1(BookID) values(1931)
insert into #TempBook1(BookID) values(1932)
insert into #TempBook1(BookID) values(1933)
Create Table #TempBook
(BookID int)
insert into #TempBook(BookID) values(1930)
2. do not insert any data into #TempBookAddress , and execute follow sql query . the exuecute time is too long, until cause timeout
select * from #TempBook1 B
inner join #TempBook b1 on B.BookID = b1.BookID
left join #TempBookAddress ba1 on B.BookID =ba1.BookID and ba1.AddressTypeID ='A'
left join #TempBookAddress ba2 on B.BookID =ba2.BookID and ba2.AddressTypeID ='B'
left join #TempBookAddress ba3 on B.BookID =ba3.BookID and ba3.AddressTypeID ='C'
left join #TempBookAddress ba4 on B.BookID =ba4.BookID and ba4.AddressTypeID ='D'
left join #TempBookAddress ba5 on B.BookID =ba5.BookID and ba5.AddressTypeID ='E'
left join #TempBookAddress ba6 on B.BookID =ba6.BookID and ba6.AddressTypeID ='F'
left join #TempBookAddress ba7 on B.BookID =ba7.BookID and ba7.AddressTypeID ='G'
left join #TempBookAddress ba8 on B.BookID =ba8.BookID and ba8.AddressTypeID ='H'
left join #TempBookAddress ba9 on B.BookID =ba9.BookID and ba9.AddressTypeID ='I'
left join #TempBookAddress ba10 on B.BookID =ba10.BookID and ba10.AddressTypeID ='J'
left join #TempBookAddress ba11 on B.BookID =ba11.BookID and ba11.AddressTypeID ='K'
left join #TempBookAddress ba12 on B.BookID =ba12.BookID and ba12.AddressTypeID ='L'
left join #TempBookAddress ba13 on B.BookID =ba13.BookID and ba13.AddressTypeID ='M'
left join #TempBookAddress ba14 on B.BookID =ba14.BookID and ba14.AddressTypeID ='N'
left join #TempBookAddress ba15 on B.BookID =ba15.BookID and ba15.AddressTypeID ='O'
left join #TempBookAddress ba16 on B.BookID =ba16.BookID and ba16.AddressTypeID ='P'
left join #TempBookAddress ba17 on B.BookID =ba17.BookID and ba17.AddressTypeID ='Q'
left join #TempBookAddress ba18 on B.BookID =ba18.BookID and ba18.AddressTypeID ='R'
left join #TempBookAddress ba19 on B.BookID =ba19.BookID and ba19.AddressTypeID ='S'
left join #TempBookAddress ba20 on B.BookID =ba20.BookID and ba20.AddressTypeID ='T'
left join #TempBookAddress ba21 on B.BookID =ba21.BookID and ba21.AddressTypeID ='U'
left join #TempBookAddress ba22 on B.BookID =ba22.BookID and ba22.AddressTypeID ='V'
left join #TempBookAddress ba23 on B.BookID =ba23.BookID and ba23.AddressTypeID ='W'
left join #TempBookAddress ba24 on B.BookID =ba24.BookID and ba24.AddressTypeID ='X'
3. if insert any data into  #TempBookAddress ,
like :insert into #TempBookAddress (BookID,AddressTypeID) values(-1,'A') before execute above query sql.Execute sql very quick . can return return result in one sec.
4. if remove some left join, just keep left join from ba1 to ba18 , the performance still ok.After ba18 , the more one we added ,the execute time have big difference
5. if do not use innerJoin for #TempBook1 , use where clause replace inner join , the sql still very quick.
this is the sql
select * from #TempBook1 B
left join #TempBookAddress ba1 on B.BookID =ba1.BookID and ba1.AddressTypeID ='A'
left join #TempBookAddress ba2 on B.BookID =ba2.BookID and ba2.AddressTypeID ='B'
left join #TempBookAddress ba3 on B.BookID =ba3.BookID and ba3.AddressTypeID ='C'
left join #TempBookAddress ba4 on B.BookID =ba4.BookID and ba4.AddressTypeID ='D'
left join #TempBookAddress ba5 on B.BookID =ba5.BookID and ba5.AddressTypeID ='E'
left join #TempBookAddress ba6 on B.BookID =ba6.BookID and ba6.AddressTypeID ='F'
left join #TempBookAddress ba7 on B.BookID =ba7.BookID and ba7.AddressTypeID ='G'
left join #TempBookAddress ba8 on B.BookID =ba8.BookID and ba8.AddressTypeID ='H'
left join #TempBookAddress ba9 on B.BookID =ba9.BookID and ba9.AddressTypeID ='I'
left join #TempBookAddress ba10 on B.BookID =ba10.BookID and ba10.AddressTypeID ='J'
left join #TempBookAddress ba11 on B.BookID =ba11.BookID and ba11.AddressTypeID ='K'
left join #TempBookAddress ba12 on B.BookID =ba12.BookID and ba12.AddressTypeID ='L'
left join #TempBookAddress ba13 on B.BookID =ba13.BookID and ba13.AddressTypeID ='M'
left join #TempBookAddress ba14 on B.BookID =ba14.BookID and ba14.AddressTypeID ='N'
left join #TempBookAddress ba15 on B.BookID =ba15.BookID and ba15.AddressTypeID ='O'
left join #TempBookAddress ba16 on B.BookID =ba16.BookID and ba16.AddressTypeID ='P'
left join #TempBookAddress ba17 on B.BookID =ba17.BookID and ba17.AddressTypeID ='Q'
left join #TempBookAddress ba18 on B.BookID =ba18.BookID and ba18.AddressTypeID ='R'
left join #TempBookAddress ba19 on B.BookID =ba19.BookID and ba19.AddressTypeID ='S'
left join #TempBookAddress ba20 on B.BookID =ba20.BookID and ba20.AddressTypeID ='T'
left join #TempBookAddress ba21 on B.BookID =ba21.BookID and ba21.AddressTypeID ='U'
left join #TempBookAddress ba22 on B.BookID =ba22.BookID and ba22.AddressTypeID ='V'
left join #TempBookAddress ba23 on B.BookID =ba23.BookID and ba23.AddressTypeID ='W'
left join #TempBookAddress ba24 on B.BookID =ba24.BookID and ba24.AddressTypeID ='X'
where B.BookID = 1930

Why do you need all these left joins?
As I understand what you need is just this instead
try this way and see if its any better
select B.*,
ba1.*
from #TempBook1 B
left join
SELECT BookID,
MAX(CASE WHEN AddressTypeID ='B' THEN yourrequiredfield1 END) AS yourrequiredfield1B,
MAX(CASE WHEN AddressTypeID ='B' THEN yourrequiredfield2 END) AS yourrequiredfield2B,
MAX(CASE WHEN AddressTypeID ='B' THEN yourrequiredfield3 END) AS yourrequiredfield3B,
MAX(CASE WHEN AddressTypeID ='C' THEN yourrequiredfieldn END) AS yourrequiredfieldnC,
MAX(CASE WHEN AddressTypeID ='C' THEN yourrequiredfield1 END) AS yourrequiredfield1C,
MAX(CASE WHEN AddressTypeID ='C' THEN yourrequiredfield2 END) AS yourrequiredfield2C,
MAX(CASE WHEN AddressTypeID ='C' THEN yourrequiredfield3 END) AS yourrequiredfield3C,
MAX(CASE WHEN AddressTypeID ='C' THEN yourrequiredfieldn END) AS yourrequiredfieldnC,
MAX(CASE WHEN AddressTypeID ='D' THEN yourrequiredfield1 END) AS yourrequiredfield1D,
MAX(CASE WHEN AddressTypeID ='D' THEN yourrequiredfield2 END) AS yourrequiredfield2D,
MAX(CASE WHEN AddressTypeID ='D' THEN yourrequiredfield3 END) AS yourrequiredfield3D,
MAX(CASE WHEN AddressTypeID ='D' THEN yourrequiredfieldn END) AS yourrequiredfieldnD,
MAX(CASE WHEN AddressTypeID ='X' THEN yourrequiredfield1 END) AS yourrequiredfield1X,
MAX(CASE WHEN AddressTypeID ='X' THEN yourrequiredfield2 END) AS yourrequiredfield2X,
MAX(CASE WHEN AddressTypeID ='X' THEN yourrequiredfield3 END) AS yourrequiredfield3X,
MAX(CASE WHEN AddressTypeID ='X' THEN yourrequiredfieldn END) AS yourrequiredfieldnX
#TempBookAddress
GROUP BY BookID)ba1
on B.BookID =ba1.BookID
where B.BookID = 1930
you need to repeat max expression for each required field in output once for each addresstype value
also see the way to do it dynamically here
http://beyondrelational.com/modules/2/blogs/70/posts/10791/dynamic-crosstab-with-multiple-pivot-columns.aspx
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page

Similar Messages

  • How do you avoid Connection Time Out when using Migration Assistant

    Connection Time Out occurred when trying to use Migration Assistant to Transfer filess from a Windows Computer to a new iMac.  What do I do to avoid this?
    I've connected the Windows computer to the iMac using an ethernet cable and both computers are on the same network.  When I started the transfer, it said it was copying the first file on both machines but nothing was happening.  Then finally it said there was a Connection Time out.  Is there anything else I need to check?

    I suspect it has something to do with your network settings on your PC. I'd recommend calling AppleCare right away. you have 90 days of free AppleCare telelphone support, they can help walk you through the process. Also if you haven't already i'd strongly recommend Pondini's guide to using Migration Assistant. You can locate it by clicking:
    http://www.pondini.org/OSX/Setup.html

  • How to get rid of the "time out" when using DAQ AI in the example program

    I try an example file called "AcqVoltageSamples_IntClkDigRef" (Visual C++ .NET). It works great. However, if the program has not recieved the data, it sent out a timeout message. How to get rid of the "time out"? I cannot find anywhere in the code. Is this a property I have to reset somewhere else?
    Thank you,
    Yajai.

    Hello Yajai,
    The example program will use the default value for timeout, 10 seconds. To change this, you will have to set the Stream.Timeout value. I inserted this function into the example and set it equal to -1, and the program will wait indefinitely for the trigger signal without timing out. Please see the attached image to how this was implemented.
    I hope this help. Let me know if you have any further questions.
    Regards,
    Sean C.
    Attachments:
    SetTimeout.bmp ‏2305 KB

  • How can I change the screen time out when using the notification screen in zoom on the IPhone?

    To clarify, when I am using Zoom and using three fingers to move around on the notification screen.  The screen goes blank even if I am actively moving my fingers across the screen to read the screen.  Why does the notification screen not recognize active movement and go blank after a peiord of time.  I have very limited sight and rely heavly on SIri, text speak, and Zoom.

    Hi BlindmanJay,
    Thanks for using Apple Support Communities.
    iPhone: About General Settings
    http://support.apple.com/kb/ta38641
    Set the amount of time before iPhone locks
    Choose General > Auto-Lock and choose a time.
    Hope this helps,
    Mario

  • Safari times out when uploading. Is there a fix?

    I'm a fan of the Safari webbrowser, BUT, for years it has pained me that it times out when uploading multiple images. I have scowered the internet in hopes to find a solution, but I find only third party plugins that don't look like they are from reliable sources.
    Chrome and Firefox can sit there and upload for any period, but Safari just stopps after 10-20 images, sometimes less. It seems more time dependant than anything else.
    I worked for tech support for a big company. We used to get loads of calls about this and we were instructed to tell people to use Chrome or Firefox.
    Why has it been so many years without a native fix? Has anyone else experienced this? Does anyone have a simple fix or a plugin from a reliable source?
    Many thanks,
    Tom

    Hi Carolyn,
    Thanks for your reply. My upload speed is 0.85Mbps.
    I'm sure this is not the issue however as it has been the same since I lived in Sweden with 100/100Mbps. When I worked at my old job with over 2 million customers uploading across Australia I would just have to advise all mac users to use another webbrowser because of this issue.
    Kind Regards,
    Tom

  • I need to host a Shared PDF on SharePoint. If it is on SharePoint can only one person comment at a time? I know documents have to be checked out when using SharePoint. I need multiple users to be able to comment in real time and see comments in real time.

    I need to host a Shared PDF on SharePoint 2010. If it is on SharePoint can only one person comment at a time? I know documents have to be checked out when using SharePoint. I need multiple users to be able to comment in real time and see comments in real time. Is this possible?

    try here:
    http://www.bbb.org
    File a complaint with them. Verizon will call you to fix the blunder.
    But remember it is always up to the customer to insure what they are getting and what it costs. Don't trust the word of a sales person who makes their living on getting that sale. Lies, deceit or false promises will be and have been used by sales people for thousands of years.
    Good Luck

  • Time outs when redirected from RDS CB to RDSH

    Hi,
    I'm troubleshooting connectivity for the following setup:
    1x RD Gateway server
    1x RD Connection Broker Server also License server
    1x RD Web server
    1x RDSH server with multiple RemoteApps
    Gateway is configured to allow bypass for local connections.  Certificate has the correct name and is successfully installed. Certificate is from an internet CA.
    When users come in over the internet RemoteApps launch pretty quickly every time.  When users connect over the LAN RemoteApps launch successfully but much slower.  When users connect over some VPN connections the connection times out when launching
    a RemoteApp.
    Over VPN I can see a successfull CAP and RAP in the Gateway Event log.  I can also see a successful connection and successful redirection from the gateway to the connection broker over HTTP.  In the SessionBroker log I can see a successful connection, but
    then when the redirect to RDSH is attempted event 819 occurs "This connection request has timed out. User could not log on to the end point within the alloted time. Remote Desktop Connection Broker will stop monitoring this connection request."
    When you connect over the LAN it takes longer but successfully redirects, and when connecting over the internet (non VPN) it connects quickly and successfully.
    Any ideas?
    Thanks
    Tim

    Hi Tim,
    What’s your server and client version you are using?
    Please uncheck the option “Bypass RD Gateway for local address” for gateway setting and verify whether there is any improvement in connections. Also as you have commented that you are receiving time out when you use VPN connection, please see whether there
    is any blockage from firewall side for not allowing VPN connection to make the connections. 
    This might also occur due to antivirus or other 3rd party related software. Because as you can connect directly from internet without any issue but there is some problem with internal LAN and VPN connection, So seems issue with internal firewall\antivirus.
    Please check whether it is not blocked or any policy applied for not allowing connection. 
    Hope it helps!
    Thanks.
    Dharmesh Solanki
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • Bug report: Screen times out when other side is no...

    Bug report: Screen times out when other side is not sharing video. The phone locks and of course the other party cannot see anything. Please fix.
    Using WP 8.1.1 Developers Preview.

    Hi and welcome to the Skype Community,
    Can you please share which platform and which device you are on?
    Also are you referring about a one-way video call here where only you are sending video, but the other party doesn't send their video back?
    Follow the latest Skype Community News
    ↓ Did my reply answer your question? Accept it as a solution to help others, Thanks. ↓

  • Time out when seinding Idocs from XI to receiving system

    Hi All,
    we have implemented a file to Idoc scenario in our XI test environment.
    When sending more than one file at a time (containing one record -> 1 Idoc after conversion) XI creates the Idocs but gets a time out when passing the Idocs to the receiving SAP 4.6C system. We find the messages blocked in transaction SM58 with the status message "Transaction recorded" and on the XI system short dumps are created with the time out error message.
    Does anyone know this problem and can give us some hints how to resolve it ?
    Thanks in advance,
    Christiane

    Christiane,
    Check your partner profiles in the target R/3 system. Use Tcode WE20 and check the inbound parameters option to see if the radio button 'Process Immediately' is switched on. If yes, change this to 'Process by background program'.
    This way, the IDOC will be created in your system with status 64. You can then use program RBDAPP01 in the R/3 system to post these IDOCs to application.
    The reason I say this is, sometimes, posting applicaitons may take a long time thereby resulting in timeout. If this is not the actual reason, atleast this will lead you to the correct problem.
    Try this and let me know what's happening.
    KK

  • WebLogic 10.3.6 Times Out When Starting Web App

    When starting our web app on WebLogic 10.3.6 using startWebLogic.sh on OEL (8 cores, 64 GB box), after about 5 to 6 minutes we receive a timeout error from WebLogic saying that it timed out trying to start the web app. The web app has some pre-computed indices to load which will take an estimated 10 to 15 minutes to load. Is there are way to control this timeout?

    The time-out you are getting is that related to a transaction?
    You can set the transaction time-out in the WebLogic console go to the JTA page for the domain, and change the value in the Timeout Seconds field.
    When you are using EJBs, you can also set the time-out on a EJB basis, instead of configuring the time-out for the whole domain.
    For example, in weblogic-ejb-jar.xml, you can configure the time-out by using:
    <weblogic-ejb-jar ...>
        <weblogic-enterprise-bean>
            <ejb-name>YOUR_EJB_NAME</ejb-name>
            <enable-call-by-reference>True</enable-call-by-reference>
            <stateless-session-descriptor>
                <pool>
                    <initial-beans-in-free-pool>25</initial-beans-in-free-pool>
                    <max-beans-in-free-pool>50</max-beans-in-free-pool>
                </pool>
            </stateless-session-descriptor>
            <transaction-descriptor>
                <trans-timeout-seconds>600</trans-timeout-seconds>
            </transaction-descriptor>
        </weblogic-enterprise-bean>
    </weblogic-ejb-jar>The transactions this EJB spawns can last for 10 minutes.

  • Internet connection times out when downloading update ios5. get to last 0.01 of date, says processing file and then says connection timed out. impossible. is there a fix?

    Internet connection times out when downloading update ios5. get to last 0.01 of data, says processing file and then says connection timed out. Is there a fix?
    I am using itunes 10.5. Update didnt work on last software but restore did work. Help

    After two days of attempts, Google & Apple searches, one Apple post stated to turn off all firewalls and virus software and keep trying since there were 6 gazillion people trying to update.  I have Windows 7 & Kaspersky and had to diable every single safety feature in Kaspersky as well as Firewalls and it finally allowed the download and update attempt. 
    Glancing at the forum, there appears to be numerous other problems with missing pictures, text problems etc after the IOS5 download but fortuneately, everything seems ok so far.  Good luck, it is frustrating!  Hattie47

  • Why is quicktime slower when using multiple mdat atoms

    Hi,
    I've been trying to generate a mov file and I noticed that the more mdat atoms I put in my mov file the more the file takes time to load on QuickTime, iTunes.
    Even worst, on the iPhone the file takes more than 3 minutes to load.
    If there are too many mdat atoms quicktime even says that the file is invalid ( error -2004 or -2002, I don't remember exactly).
    Why is quicktime/iTunes slower when using multiple mdat atoms ?
    Thanks,

    Yeah! Problem solved: It's a QT issue.
    Cause: Mac Update Software downloaded a faulty QT.
    Solution: Download QT from Apple's QT site.
    Great to have the Video back

  • System is showing time out when run in background

    Dear all,
    We have two systems: One R/3 and EBP. We have made one report where the remote function module will be called from R/3 to EBP. There are 4 lakhs data in SAP. We are sending 10000 data as package in internal table and getting the corresponding output. But the system is showing time out when the report has run in background. Can you please suggest how the process can be improved so that the timeout can be avoided.
    Thanks and regards,
    Atanu

    Hi,
    Try to fetch records in smaller chunks and process them.  For example, if you are trying to fetch records for one year, instead of single query, try to fetch in 12 sets for each month.  Fetch first month and process the records and put them in the output internal table.  Then go for next month and so on.  Anyway your program is running in background.  There will not be any user complaint also.  The solution might sound bit funny.  But it works.
    Regards,
    Hema

  • Run time error when using search

    I get a run time error when using the search in iTunes store. Running current iTunes version.

    Duplicate post -- Client ADI display A runtime error in Office 2010

  • HT4972 iTunes times out when trying to download iOS 5.1

    iTunes times out when trying to download iOS 5.1 - can anyone help? Can I download via a browser and then install that way?
    Looking here http://osxdaily.com/2012/03/07/ios-5-1-download/ - I can download an ipsw file - how would I get that to install on my iPhone4?
    Help!
    Cheers
    P.S. My iPhone4 is on Orange UK - is this a GSM one? or CDMA???

    Hi,
    Tap Settings > General > Reset > Reset Network Settings
    Now restart your iPad.  Hold the On/Off Sleep/Wake button down until the red slider appears. Slide your finger across the slider to turn off iPhone. To turn iPhone back on, press and hold the On/Off Sleep/Wake button until the Apple logo appears.
    If that didn't help, you need to post in the iPad forum here.
    This is the forum for Safari for the Mac OS X.

Maybe you are looking for

  • Layout in me2o

    Hi, My client is using subcontracting but is not satisfied be the standard layout in Transaction me2o. The list build up like -      SC requisition in 1th line      SC Order in 2nd line      ... and so on. Instead I would like a view sorted by requis

  • [vifm] open file with...

    Hello guys, I'm quite impressed about Vifm file manager. But what I still didn't find out is how I can specify default apps for filetypes I'd like to open with vifm. For example I'd like to open images with feh and not with Vi(m) itself as it is prec

  • I randomly get this: name of your computer is already in use

    Does anyone know how to fix this? I have comcast that is IPv6 and probabnly IPv4 as well. I have the tower Airport Extreme, firmware updated MacPro, 10.9.2, Airport card turned off, using only ethernet. One Trendnet Gigabyte Green switch. I have been

  • Pointers Needed on Movement from Blocked Stock to Unrestricted Stock !

    Hi Gurus, I have a scenario wherein I need to take care of "Movement from Blocked Stock to Unrestricted Stock using Movement type 343 and in the next step need to do Material to Material transfer using movement type 309" My Query is: 1. What does it

  • Fixing automatic printing of material document for goods movement type 101

    Hi experts, I have a situation, where I want to fix automatically printing of material documents good receipt and transfer posting related to movement type : 101- GR for plant XYZW to the printer AB12 with output type WE03 " GR note version 3" Langua