Note that there are some explanatory texts on larger screens.

plurals
  1. POAnother approach for long SQL Query
    primarykey
    data
    text
    <p>I have a query whose purpose is to retrieve the records according to search parameters. Other parameters are fine but there's one field called "Member". When users put a part of name to that "Member" text box, it should return all the records in which that "Member" has been involved in different roles. I had quite a complex query but it was fine and only took a second before the where clause is put. My previous where clause was like</p> <pre><code>WHERE (( C.IDNumber LIKE '%11%' AND C.OriginalIDNumber LIKE '%11%' AND H.UserDisplayName LIKE '%david%' OR C.SubmittedBy LIKE '%david%' OR J.UserID IN( Select UserID from USER_PROFILE where UserDisplayName LIKE '%david%') OR L.UserID IN( Select UserID from USER_PROFILE where UserDisplayName LIKE '%david%') OR X.DepartmentHead IN (Select UserID from USER_PROFILE where UserDisplayName LIKE '%david%') OR E.DepartmentHead IN (Select UserID from USER_PROFILE where UserDisplayName LIKE '%david%') OR N.UserID IN (Select UserID from USER_PROFILE where UserDisplayName LIKE '%david%') OR O.UserID IN (Select UserID from USER_PROFILE where UserDisplayName LIKE '%david%') OR Y.OrganisationAdmin IN (Select UserID from USER_PROFILE where UserDisplayName LIKE '%david%') OR Y.FinalApprovalAuthority IN (Select UserID from USER_PROFILE where UserDisplayName LIKE '%david%') OR Y.OrganisationFinance IN (Select UserID from USER_PROFILE where UserDisplayName LIKE '%david%') OR Z.UserID IN (Select UserID from USER_PROFILE where UserDisplayName LIKE '%david%'))) AND (C.Status&lt;&gt;'Draft') </code></pre> <p>J,L,X,E and so on are different tables that I must join. I took more than a minute and I modifed it into</p> <pre><code>WHERE (( C.IDNumber LIKE '%11%' AND C.OriginalIDNumber LIKE '%11%' AND H.UserDisplayName LIKE '%david%' OR C.SubmittedBy LIKE '%david%' OR W.UserDisplayName LIKE '%david%' OR AA.UserDisplayName LIKE '%david%' OR BB.UserDisplayName LIKE '%david%' OR CC.UserDisplayName LIKE '%david%' OR DD.UserDisplayName LIKE '%david%' OR EE.UserDisplayName LIKE '%david%' OR FF.UserDisplayName LIKE '%david%' OR GG.UserDisplayName LIKE '%david%' OR HH.UserDisplayName LIKE '%david%' OR II.UserDisplayName LIKE '%david%')) AND (C.Status&lt;&gt;'Draft') </code></pre> <p>by putting left outer join for User_Profile table with J,L,X,E and so on. AA, BB, CC and so on are new User_Profile tables to be joined.</p> <p>But it is still taking 30 seconds which leads the "Timeout Expired" error when I run the application. Any other approach to reduce the time taking by query?</p> <p>I'm using MSSQL 2008.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload