Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mroll
Starting Member
4 Posts |
Posted - 2010-01-14 : 10:23:05
|
| I have the following stored procedure that returns my results. I need to replace the IsIndexed column with a case statement that checks the column in a new joined table (it may be null). I am not sure how to accomplish this and it is kicking my butt. Any help would be appreciated.WORKING SQL excerpted from Stored Procedure:select PLS.Credentials, PLS.OriginalCitation, PLS.CriticalSummaryConclusion, PLS.ClinicalQuestion, PLS.ReviewConclusionDate, PLS.ReviewMethods, PLS.MainResults, PLS.Conclusions, PLS.SourceOfFunding, PLS.ImportanceAndContext, PLS.StrengthsAndLimitationsOfSR, PLS.StrengthsAndLimitationsOfEvidence, PLS.ImplicationsForDentalPractice, PLS.GeneralComments, PLS.JADAURL, PLS.AddToJADA, PLS.Status as PlainLanguageSummaryStatus, PLS.SystematicReviewId, PLS.Id as PLSId,-- REPLACE THE CASE BELOW ... case PLS.Indexed when 1 then 'Yes' else 'No' end as IsIndexed,-- ... WITH THIS-- CASE WHEN C.ClinicalTopicId is null THEN 'No' ELSE 'Yes' END as IsIndexed, case PLS.SetPriority when 1 then 'Yes' else 'No' end as IsSetPriority, SR.*, LastName+', '+FirstName as UserName, dateadd(d,@DueDays,CS.CreatedDate) as DueDate from ADCollaborationTeam CT, ADCollaborationTeamUsers TU, ADUsers U, ADSystematicReview SR, ADPlainLanguageSummary PLS, ADCriticalSummary CS left join ( select (sum(cast(RateSummary as float))/Count(SystematicReviewId)) RateSummary,SystematicReviewId from ADPublicRatingCriticalSummary Group by SystematicReviewId) PR on PR.SystematicReviewId = CS.SystematicReviewId-- WHERE DO I ADD THE JOIN FOR CategoryClinicalTopic ???-- left join -- (select distinct ClinicalTopicId from ADCategoryClinicalTopic) C -- on SR.SRId=C.ClinicalTopicId where PLS.CriticalSummaryId=CS.Id and CS.SystematicReviewId=SR.Id and SR.Id=CT.ClinicalTopicId and CT.Id=TU.CollaborationTeamId and TU.UserId=U.Id and TU.RoleId=100 and TU.IsPrimaryAER = 1I need to know if the PLS.Id exists in the CategoryClinicalTopicId table so I would add something like this (as commnted above):left join (select distinct ClinicalTopicId from ADCategoryClinicalTopic) C on SR.SRId=C.ClinicalTopicIdAny help would be GREATLY appreciated.Mike |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-14 : 10:28:27
|
| [code]select PLS.Credentials,PLS.OriginalCitation,PLS.CriticalSummaryConclusion,PLS.ClinicalQuestion,PLS.ReviewConclusionDate,PLS.ReviewMethods,PLS.MainResults,PLS.Conclusions,PLS.SourceOfFunding,PLS.ImportanceAndContext,PLS.StrengthsAndLimitationsOfSR,PLS.StrengthsAndLimitationsOfEvidence,PLS.ImplicationsForDentalPractice,PLS.GeneralComments,PLS.JADAURL,PLS.AddToJADA,PLS.Status as PlainLanguageSummaryStatus,PLS.SystematicReviewId,PLS.Id as PLSId,CASE WHEN C.ClinicalTopicId is null THEN 'No' ELSE 'Yes' END as IsIndexed,case PLS.SetPrioritywhen 1 then 'Yes'else 'No'end as IsSetPriority,SR.*,LastName+', '+FirstName as UserName,dateadd(d,@DueDays,CS.CreatedDate) as DueDatefrom ADCollaborationTeam CTjoin ADCollaborationTeamUsers TUon CT.Id=TU.CollaborationTeamId join ADUsers Uon TU.UserId=U.Idjoin ADSystematicReview SRon SR.Id=CT.ClinicalTopicIdjoin ADCriticalSummary CSon CS.SystematicReviewId=SR.Id join ADPlainLanguageSummary PLSon PLS.CriticalSummaryId=CS.Idleft join ( select (sum(cast(RateSummary as float))/Count(SystematicReviewId)) RateSummary,SystematicReviewIdfrom ADPublicRatingCriticalSummary Group by SystematicReviewId) PRon PR.SystematicReviewId = CS.SystematicReviewIdleft join (select distinct ClinicalTopicId from ADCategoryClinicalTopic) C on SR.SRId=C.ClinicalTopicIdwhere TU.RoleId=100 and TU.IsPrimaryAER = 1[/code] |
 |
|
|
|
|
|
|
|