Solved

Improve query with different syntax ?

Posted on 2011-09-08
4
222 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query assistance 16 46
T-SQL: Stored Procedure Syntax 3 34
Finding Where Clause Value in SQL Views and SP 21 41
SQL Syntax 6 31
In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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