遞歸查詢下級介紹人代碼

id RmtCustomerID introducer
XX XXXXXXX XXXXX
XX XXXXXXX XXXXX

// 遞歸查找介紹人ID

 procedure GetIntroducedCusIDs(ParentID: string; var IDS: string);
  var
    TmpSQL: string;
    IntroducedID: string;
    TempQuery: ThDataSet;
  begin
    // 查詢被介紹的人
    TempQuery := CreateADOQuery;
    try
      TmpSQL := 'select id from bd_Customers where RmtCustomerID=' + QuotedStr(ParentID);
      OpenSql(TempQuery, TmpSQL);
      if TempQuery.RecordCount <> 0 then
      begin
        TempQuery.First;
        while not TempQuery.Eof do
        begin
          IntroducedID := TempQuery.fieldByname('id').AsString;
          IDS := IDS + IntroducedID + ',';
          GetIntroducedCusIDs(IntroducedID,IDS);
          TempQuery.Next;
        end;
      end;
    finally
      TempQuery.Free;
    end;
  end;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章