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
Solved

Improve query with different syntax ?

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with query 3 31
Sql Server group by 10 44
2 IIF's in Access query 25 44
Access join syntax when converting to T-SQL query 4 34
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…
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 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