procedure InsertQuery(ServiceId: string);
var
  rQueryResp: QueryResp^;
  Qry: TADOQuery;
begin
  Qry := tadoquery.Create(nil);
  new(rQueryResp);
  try
      if (PQuery(pchar(formatdatetime('yyyymmdd', now())), 0, pchar(serviceid), rQueryResp)) = 0 then
      begin
        with Qry do
        begin
          ConnectionString := 'FILE NAME=newsms.udl';
          close;
          sql.Clear;
          sql.Text := 'insert into cmppquery(serviceid,nMT_TLMSG,nMT_TLusr,nMT_Scs,nMT_WT,nMT_FL,nMO_Scs,nMO_WT,nMO_FL)' +
            ' values(' + '''' + serviceid + '''' + ',' + inttostr(rQueryResp^.nMT_TLMSG) + ',' +
            inttostr(rQueryResp^.nMT_TLusr) + ',' +
            inttostr(rQueryResp^.nMT_Scs) + ',' +
            inttostr(rQueryResp^.nMT_WT) + ',' +
            inttostr(rQueryResp^.nMT_FL) + ',' +
            inttostr(rQueryResp^.nMO_Scs) + ',' +
            inttostr(rQueryResp^.nMO_WT) + ',' +
            inttostr(rQueryResp^.nMO_FL) + ')';
          try
            execsql;
          except
          end;  
        end;
      end;
  finally
    dispose(rQueryResp);
    qry.Free;
  end;end;