Hola...
Si te entendí bien, lo que tu código debe hacer es algo así:
Código:
+--------+----------+---------+---------+---------+---------+---------+
| Numero | Pregunta | Opcion1 | Opcion2 | Opcion3 | Opcion4 | Opcion5 |
+--------+----------+---------+---------+---------+---------+---------+
| 1 | Sección | | | | | |
+--------+----------+---------+---------+---------+---------+---------+
| 1.1 | ¿Como es.| 1 | 2 | | | 5 |
+--------+----------+---------+---------+---------+---------+---------+
| 1.2 | ¿Cual es.| 1 | | 3 | | 5 |
+--------+----------+---------+---------+---------+---------+---------+
| 1.3 | ¿Donde...| 1 | 2 | 3 | | |
+--------+----------+---------+---------+---------+---------+---------+
| 2 | Sección | | | | | |
+--------+----------+---------+---------+---------+---------+---------+
| 2.1 | ¿Como es.| 1 | 2 | | | 5 |
+--------+----------+---------+---------+---------+---------+---------+
| 2.2 | ¿Cual es.| 1 | | 3 | | 5 |
+--------+----------+---------+---------+---------+---------+---------+
| 2.3 | ¿Donde...| 1 | 2 | 3 | | |
+--------+----------+---------+---------+---------+---------+---------+
Si lo anterior es cierto, prueba con este código:
Código Delphi
[-]
procedure TForm1.BitBtnGenerarClick(Sender: TObject);
var
X: Integer;
Valor: Integer;
Evalua: string;
begin
Evalua := copy(cmbEvaluacion.Text, 0, Pos('-', cmbEvaluacion.Text) - 1);
Query1.Close;
Query1.SQL.Text := Format('select det_version from det_evaluacion ' +
'where det_eval = ''%s''', [Evalua]);
Query1.Open;
lblVersion.Caption := Query1.FieldByName('det_version').AsString;
Query1.Close;
Query1.SQL.Text := Format('select * from det_evaluacion ' +
'where det_eval = ''%s'' and det_tipo = 0 and ' +
'det_valor = 0 order by det_clave', [Evalua]);
Query1.Open;
X := 1;
while not Query1.Eof do
begin
sgEvaluacion.RowCount := X + 1; sgEvaluacion.Cells[0, X] := Query1.FieldByName('det_pregunta').AsString;
sgEvaluacion.Cells[1, X] := Query1.FieldByName('det_pregunta').AsString;
Query2.Close;
Query2.SQL.Text := Format('select * from det_evaluacion ' +
'where det_eval = ''%s'' and det_tipo = 1 and ' +
'det_clave like ''%s.%%'' and det_valor = 0 ' +
'order by det_clave', [Evalua, Query1.FieldByName['det_clave'].AsString]);
Query2.Open;
while not Eof do
begin
Inc(X);
sgEvaluacion.RowCount := X + 1; sgEvaluacion.Cells[0, X] := Query2.FieldByName('det_clave').AsString;
sgEvaluacion.Cells[1, X] := Query2.FieldByName('det_pregunta').AsString;
Query3.Close;
Query3.SQL.Text := Format('select det_valor from det_evaluacion ' +
'where det_eval = ''%s'' and det_clave like ''%s.%%'' and '
'det_tipo = 2 order by det_valor asc', [Evalua,
Query1.FieldByName('det_clave'].AsString]);
Query3.Open;
while not Query3.Eof do
begin
Valor := Query3.FieldByName('det_valor').AsInteger;
sgEvaluacion.Cells[Valor + 1, X] := IntToStr(Valor);
Query3.Next;
end;
sgEvaluacion.Cells[7, X] := 'Resultado';
Query2.Next
end;
Inc(X); Query1.next
end
end;
Saludos...