-1

名前、ビジネス名、大学名、スキル名に基づいてテーブルを検索したい。

ある時は名前で検索し、別の時は会社名で、別の時は大学名で同様に検索するとしますが、名前を入力して検索ボタンをクリックすると、正しく表示されます。しかし、ビジネス名または大学名を入力すると、適切に取得できず、ビジネス名の列がすべてnullのように空になります。

次のようなストアド プロシージャを作成しました。

ALTER PROCEDURE [dbo].[SearchPeople_test]
(
      @FirstName nvarchar(255),
      @Location nvarchar(100),
      @MembershipUserID uniqueidentifier,
      @UniversityName nvarchar(255),
      @Postcode nvarchar(20),
      @BusinessName nvarchar(255),
      @AssociateMemberID uniqueidentifier,
      @SkillName nvarchar(255),
      @Debits int,
      @Gender int
  )
AS
BEGIN

    SET @SkillName = [dbo].[fnGetMemberskills](@AssociateMemberID)
    SET @Debits = [dbo].[fnGetMembersSpentCredits](@AssociateMemberID)
    SET NOCOUNT ON;

SELECT  DISTINCT  AssociateMember.ID AS ID       
        ,AssociateMember.Firstname AS FirstName        
        ,AssociateMember.Lastname AS LastName
        ,Address.Location AS Location
        ,Address.City AS City
        ,BusinessProfile.BusinessName
        ,EducationHistory.UniversityName
        ,AssociateMember.MembershipUserID AS MembershipUserID
        ,EmploymentHistory.JobTitle AS JobTitle
        ,AssociateMember.MemberPhotoUrl AS MemberPhotoUrl
        ,aspnet_Membership.Email AS Email
        ,AssociateMemberJourneyContent.JourneyContent AS JourneyContent
        ,([dbo].[fnGetMemberskills](AssociateMember.ID))  AS MemberSkillList
        ,([dbo].[fnGetMembersSpentCredits](AssociateMember.ID))  AS Debits              
FROM 
    AssociateMember 
INNER JOIN
    aspnet_Membership 
    ON AssociateMember.MembershipUserID=aspnet_Membership.UserId 
left outer join  MemberAddressLink      
    ON AssociateMember.ID=MemberAddressLink.MemberID

left outer join
    Address 
    ON Address.ID=MemberAddressLink.AddressID 

left outer join 
    EmploymentHistory 
    ON AssociateMember.ID=EmploymentHistory.MemberID     

left outer join   
    EducationHistory 
    ON EducationHistory.MemberID=AssociateMember.ID 

left outer join  
    MemberEmploymentHistory 
    ON AssociateMember.ID=MemberEmploymentHistory.MemberID

left outer join 
    BusinessProfile 
    ON BusinessProfile.ID=MemberEmploymentHistory.BusinessProfileID 

left outer join
    MemberSkill 
    ON MemberSkill.MemberID=AssociateMember.ID

left outer join 
    SkillType 
    ON SkillType.ID = MemberSkill.SkillID AND MemberSkill.MemberID=AssociateMember.ID
left outer join
    AssociateMemberJourneyContent
    ON AssociateMember.ID=AssociateMemberJourneyContent.AssociateMemberID

where
((Address.Location)=ISNULL(@Location,Address.Location) and (MemberAddressLink.IsDefault=1)
                 OR (Address.Location like '%'+ @Location+'%')or (Address.Location is null) ) and

 (AssociateMemberJourneyContent.JourneyContentTypeID=1 OR  AssociateMemberJourneyContent.JourneyContentTypeID IS NULL) AND


(((BusinessProfile.BusinessName)=ISNULL(@BusinessName,BusinessProfile.BusinessName) 
                             OR (BusinessProfile.BusinessName like '%'+@BusinessName+'%')or(BusinessProfile.BusinessName is null))
                              AND
                             ((MemberEmploymentHistory.StartDate)=(SELECT  MAX(StartDate) FROM MemberEmploymentHistory 
WHERE MemberEmploymentHistory.MemberID=AssociateMember.ID) OR (MemberEmploymentHistory.StartDate IS NULL))) AND


((AssociateMember.Firstname)=ISNULL(@FirstName,AssociateMember.Firstname) 
                          OR (AssociateMember.Firstname like '%'+@FirstName+'%')OR (AssociateMember.Firstname IS NULL)) AND 



((Address.Postcode)=ISNULL(@Postcode,Address.Postcode) 
                 OR (Address.Postcode like '%'+@Postcode+'%') OR (Address.Postcode IS NULL)) AND

(((EducationHistory.UniversityName)=ISNULL(@UniversityName,EducationHistory.UniversityName) 
                OR (EducationHistory.UniversityName like '%'+@UniversityName+'%') OR (EducationHistory.UniversityName IS NULL)) AND
            ((EducationHistory.StartDate)=(SELECT  MAX(StartDate) FROM EducationHistory 
WHERE EducationHistory.MemberID=AssociateMember.ID) OR (EducationHistory.StartDate IS NULL) ))AND



((AssociateMember.GenderID)=ISNULL(AssociateMember.GenderID,@Gender) 
                          OR (AssociateMember.GenderID IS NULL)) AND


((EmploymentHistory.StartDate)=(SELECT MAX(StartDate) FROM EmploymentHistory 
WHERE EmploymentHistory.MemberID=AssociateMember.ID)OR (EmploymentHistory.StartDate IS NULL)   ) 
end
4

1 に答える 1

0

すべてを 1 回のヒットで実行しようとするのではなく、分割して、最初に列のクエリを作成し、実行します。それから次のためにそれをして、それを実行してください。次に、最後に 2 つのクエリを結合し、実行し、3 つのクエリを結合して実行するなどです。期待どおりの結果が得られない場合は、何を行っているかを分析します。

于 2013-04-23T16:51:51.943 に答える