unit U_ProgressUpdate;

interface

uses
  System.SysUtils, ADODB;

function TradeMarketProgressUpdate(AdoCmd: TADOQuery; MTMSIdS: string): Boolean;

function TradeMarketProgressUpdateByTMMID(AdoCmd: TADOQuery; MTMMID: string): Boolean;

implementation

function TradeMarketProgressUpdate(AdoCmd: TADOQuery; MTMSIdS: string): Boolean;
begin
  with AdoCmd do
  begin
    close;
    sql.Clear;
    sql.Add('exec P_Trade_Market_UpOut');
    sql.Add('@TMSIdS=' + quotedstr(Trim(MTMSIdS)));
    Open;
  end;
  Result := True;
end;

function TradeMarketProgressUpdateByTMMID(AdoCmd: TADOQuery; MTMMID: string): Boolean;
var
  MTMSIdS: string;
begin
  with AdoCmd do
  begin
    close;
    sql.Clear;
    sql.Add('select distinct TMSId from Trade_Market_sub A ');
    sql.Add('where EXISTS(select X.RTValue from [dbo].[F_Tool_SplitString](' + quotedstr(Trim(MTMMID)) + ','','')  X where X.RTValue=A.TMMID )  ');
    Open;
    while not Eof do
    begin
      if Trim(MTMSIdS) = '' then
        MTMSIdS := FieldByName('TMSId').AsString
      else
        MTMSIdS := MTMSIdS + ',' + FieldByName('TMSId').AsString;
      next;
    end;
  end;

  with AdoCmd do
  begin
    close;
    sql.Clear;
    sql.Add('exec P_Trade_Market_UpOut');
    sql.Add('@TMSIdS=' + quotedstr(Trim(MTMSIdS)));
    Open;
  end;

  Result := True;

end;

end.

