Solved

Improve query with different syntax ?

Posted on 2011-09-08
4
219 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
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
Comment Utility
 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
Comment Utility
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
Comment Utility
 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
Comment Utility
Yeah, that works, thanks so much !
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now