Solved

Improve query with different syntax ?

Posted on 2011-09-08
4
223 Views
Last Modified: 2012-05-12
I have been working on this query for a while now, this is as short as I can make it but I am not sure it is the best approach, it takes about 3 min to return the results. Any advice on how to use a different approach or syntax is greatly appreciated

----

SELECT
  t0.activityid as id,
  t0.ActName as actdesc,
  t0.dateinitiated as datestarted,
  t0.lastmodified as datefinished,
  t0.processtep as repeat,
  t0.Partylist as apptype
FROM
(
  SELECT activityid,ActName,dateinitiated,lastmodified, processtep, Partylist, sent_by, CaseId  
  FROM dbo.Activities
  WHERE Activities.FirmId = 2
    AND  (Activities.ActType = 'Calendar')  
    AND sent_by = 1713
) t0
LEFT JOIN dbo.Cases
     ON t0.CaseId = dbo.Cases.Id
LEFT JOIN dbo.Atts
  ON dbo.Atts.CaseId = dbo.Cases.Id    
INNER JOIN Users
  ON sent_by = Users.UserId

----
0
Comment
Question by:amucinobluedot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 36508036
 SELECT
  t0.activityid as id,
  t0.ActName as actdesc,
  t0.dateinitiated as datestarted,
  t0.lastmodified as datefinished,
  t0.processtep as repeat,
  t0.Partylist as apptype
  FROM dbo.Activities t0
 INNER JOIN Users
  ON sent_by = Users.UserId
LEFT JOIN dbo.Cases
     ON t0.CaseId = dbo.Cases.Id
LEFT JOIN dbo.Atts
  ON dbo.Atts.CaseId = dbo.Cases.Id  
 WHERE Activities.FirmId = 2
    AND  (Activities.ActType = 'Calendar')  
    AND sent_by = 1713
0
 

Author Comment

by:amucinobluedot
ID: 36508059
That query returns this errors:

Msg 4104, Level 16, State 1, Line 15
The multi-part identifier "Activities.FirmId" could not be bound.
Msg 4104, Level 16, State 1, Line 16
The multi-part identifier "Activities.ActType" could not be bound.
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 36508097
 SELECT
  t0.activityid as id,
  t0.ActName as actdesc,
  t0.dateinitiated as datestarted,
  t0.lastmodified as datefinished,
  t0.processtep as repeat,
  t0.Partylist as apptype
  FROM dbo.Activities t0
 INNER JOIN Users
  ON sent_by = Users.UserId
LEFT JOIN dbo.Cases
     ON t0.CaseId = dbo.Cases.Id
LEFT JOIN dbo.Atts
  ON dbo.Atts.CaseId = dbo.Cases.Id  
 WHERE t0.FirmId = 2
    AND  (t0.ActType = 'Calendar')  
    AND sent_by = 1713
0
 

Author Comment

by:amucinobluedot
ID: 36508112
Yeah, that works, thanks so much !
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question