Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Internal error: An expression services limit has been reached. Please look for potentially complex

Status
Not open for further replies.

Motlatjo

Programmer
Oct 11, 2011
76
ZA
Hi

When i execute my report, i get an error, 'Internal error: An expression services limit has been reached. Please look for potentially complex expressions in your query, and try to simplify them.'

below is the query, Please help me simplify


SELECT Date,
SUM(Four) No_of_QA_CASEs_allocated,
SUM(One) Team_Leader_review_results_FROM_quality_ASsessor,
SUM(Five) No_of_CASEs_sent_for_moderation,
SUM(Six) No_of_moderated_surveys_returned_to_Team_Leader,
SUM(Three) No_of_CASEs_FINalized_By_Agent,
SUM(Seven) No_of_CASEs_FINalised_Auto_Completed

FROM(
SELECT az.DATE Date,
az.QACASENo,
CASE WHEN Status = 'Quality ASsessor evaluation for origINal case case sent to Team Leader review' THEN 1 ELSE 0 END One,
--SUM(CASE WHEN Status = 'Quality ASsessor evaluation hAS been submitted for origINal CASE' THEN 1 ELSE 0 END) Two,
CASE WHEN Status = 'Quality Evaluation case fINalised' THEN 1 ELSE 0 END Three,
CASE WHEN Status = 'Quality Evaluation case has been INitiated for evaluation of origINal CASE' THEN 1 ELSE 0 END Four,
CASE WHEN Status = 'Quality evaluation case sent to Specialist for 2nd review' THEN 1 ELSE 0 END Five,
CASE WHEN Status = 'Quality Specialist evaluation for original CASE sent to Team Leader for review' THEN 1 ELSE 0 END Six,
CASE WHEN Status = 'Team Lead assessment case auto completed' THEN 1 ELSE 0 END Seven
FROM(
SELECT CASENo QACASENo,
Status,
Date
FROM StatusTracks
WHERE Date BETWEEN @DateFROM and @DateTo

) az INNER JOIN

(
SELECT QACASENO,
Date,
TeamMember,
an.TEAMLEADERSID
FROM
(
SELECT DistINct QACASENO,
Date,
TeamMember
FROM(
SELECT
suv.CASEClASsification,
suv.Date,
suv.EvaluationDate,
suv.EvaluationType,
suv.QACASENO,
suv.SurveyName,
suv.Tier,
suv.StepNo,
c.TaxType,
c.Area,
c.CASENO OrigCASENo,
c.OrigCASEDate,
c.TeamMember
FROM
(
SELECT ss.ASsessorID,
ss.CASEClASsification,
ss.Date,
ss.EvaluationCASENo,
ss.EvaluationDate,
ss.EvaluationType,
ss.QACASENO,
ss.SpecialistID,
ss.StepNo,
ss.SurveyName,
ss.TeamLeaderID,
ss.Tier
FROM
(
SELECT Date EvaluationDate,
CASEClASsification,
DATE,
CASE WHEN SYSID = 381970529 THEN ASsignedRole ELSE '' END ASsessorID,
CASE WHEN SYSID = 1250902731 THEN ASsignedRole ELSE '' END TeamLeaderID,
CASE WHEN SYSID = 1734455418 THEN ASsignedRole ELSE '' END SpecialistID,
QACASENO,
EvaluationCASENo,
COALESCE(Tier, 'No Tier') Tier,
SurveyName,
EvaluationType,
StepNo,
QABUSINESSAREA
FROM CASEsSurvey
) ss
--WHERE QACASENO IN (1456587, 1456362, 1456583, 1456819, 1456823, 1456817, 1456880,1454203, 1454204)
WHERE DATE BETWEEN @DateFROM and @DateTo
And CASEClASsification IN (@CASEClASsification)
And EvaluationType IN (@EvaluationType)
And SurveyName IN (@SurveyName)
And Tier IN (@Tier)
And QABUSINESSAREA IN (@QABusINessArea)

) suv

LEFT OUTER JOIN
(
SELECT CASENO,
TaxType,
OrigCASEDate,
TeamMember,
Area
FROM(
SELECT CASENO,
TMSTAMP,
DateCreated OrigCASEDate,
CASE CharINdex('\',USRID) WHEN 0 THEN USRID
ELSE right(USRID ,Len(USRID) - CharINdex('\',USRID)) END TeamMember,
AreaCode + ' : ' + Area Area,
CASE WHEN REFNO IN (1, 8, 11) THEN 'ITS'
WHEN REFNO IN (2, 5, 6) THEN 'PAYE'
WHEN REFNO = 3 THEN 'VAT'
WHEN REFNO IN (4, 9, 10) THEN 'Customs' ELSE 'NullTax' END TaxType
FROM CASES
) aa
WHERE aa.TaxType IN (@TaxType)
AND aa.Area IN (@Area)
And TeamMember IN (@TeamMember)

) c On c.CASENO = suv.EvaluationCASENo



) alls LEFT OUTER JOIN (SELECT AccessorName AccessorName, AccessorSID, Started, StepNo
FROM TempAccessor
WHERE AccessorSID IN (@QAASsessorSID)
AND CAST(Started AS Date) BETWEEN @DateFROM and @DateTo

) acc On acc.StepNo = alls.StepNo
and alls.Date = CAST(acc.Started AS Date)

LEFT OUTER JOIN (SELECT StepNo, TeamLeaderName, TeamLeaderSID, Started
FROM TempTeamLeader
WHERE CAST(Started AS Date) BETWEEN @DateFROM and @DateTo
--GROUP by Started, TeamLeaderName, TeamLeaderSID
) tl On tl.StepNo = alls.StepNo
and alls.Date = CAST(tl.Started AS Date)

LEFT OUTER JOIN (SELECT StepNo, SpecialistSID, Started
FROM TempSpecialist
WHERE SpecialistSID IN (@QASpecialistSID)
AND CAST(Started AS Date) BETWEEN @DateFROM and @DateTo

) spl On spl.StepNo = alls.StepNo
and alls.Date = CAST(spl.Started AS Date)

LEFT OUTER JOIN (SELECT StepNo, TeamLeaderName, TeamLeaderSID, Started
FROM TempTeamLeader2Review
WHERE CAST(Started AS Date) BETWEEN @DateFROM and @DateTo
--GROUP by Started, TeamLeaderName, TeamLeaderSID
) tl1 On tl1.StepNo = alls.StepNo
and alls.Date = CAST(tl1.Started AS Date)

--
) aa LEFT OUTER JOIN (SELECT AGENTSID,
TEAMLEADERSID
FROM AGENTTEAMLEAD
WHERE TEAMLEADERSID IN (@TeamLeaderSID)) an on aa.TeamMember = an.AGENTSID
) aq on az.Date = aq.Date
AND aq.QACASENO = az.QACASENo
GROUP By az.QACASENo, az.Status, az.DATE
) yy
GROUP by Date

 
how many nested tables do you have in total? what version of sql?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top