![]() |
![]() |
| Paypal | FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
|||||||
| Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
![]() |
|
|
Herramientas | Buscar en Tema | Desplegado |
|
#1
|
||||
|
||||
|
Consulta que en función de un campo saque desglose o nombre del grupo
Utilizando Firebird 1.0 tengo dos tablas
Código:
CREATE TABLE SES'+Part+'GRU('+
'SESGRU_CODIGO N4 NOT NULL,'+
'SESGRU_TIPO CODIGO NOT NULL,'+
'SESGRU_DESCRIP DESCRIP,'+
'SESGRU_T1 DESCRIP,'+
'SESGRU_T2 DESCRIP,'+
'SESGRU_COD1 CODIGO,'+
'SESGRU_COD2 CODIGO,'+
'SESGRU_COD3 CODIGO,'+
'SESGRU_MOSTRAR LOGICO,'+
'SESGRU_ACTIVO LOGICO,'+
'primary key (SESGRU_CODIGO))';
Código:
CREATE TABLE SES'+Part+'ASU('+
'SESASU_CODIGO CODIGO NOT NULL,'+
'SESASU_SESION CODIGO NOT NULL,'+
'SESASU_GRUPO N4,'+
'SESASU_ORDEN CODIGO NOT NULL,'+
'SESASU_ASUNTO BLOB SUB_TYPE 1 SEGMENT SIZE 80,'+
'SESASU_DEBATE BLOB SUB_TYPE 1 SEGMENT SIZE 80,'+
'SESASU_RESOLU BLOB SUB_TYPE 1 SEGMENT SIZE 80,'+
'primary key (SESASU_CODIGO),'+
'foreign key (SESASU_SESION) references SES'+Part+'DAT(SESDAT_CODIGO)on delete cascade,'+
'foreign key (SESASU_GRUPO) references SES'+Part+'GRU(SESGRU_CODIGO))';
Podría hacerse esto con una SQL o tendré que hacer un recorrido manual por los asuntos e ir seleccionandolo sobre la marcha? |
|
#2
|
||||
|
||||
|
Hola.
¿ Puedes actualizarte a Firebird 1.5 ? En esta caso seguramente te será útil poder hacer construcciones CASE dentro de una consulta. select ..., (CASE WHEN SESGRU_MOSTRAR = 1 THEN SEASU_ASUNTO ELSE SESGRU_DESCRIP) as ASUNTO from ... NOTA: Consulta las Release Notes de Firebird 1.5 para ampliar la información de la construcción CASE. Aquí las puedes encontrar en castellano. http://www.ibphoenix.com/downloads/F...tesSpanish.pdf Saludos.
__________________
Marc Guillot (Hi ha 10 tipus de persones, els que saben binari i els que no). |
|
#3
|
||||
|
||||
|
He probado:
Código:
with QueryAsu do
begin
SQL.Clear;
SQL.Add('select SESASU_CODIGO,SESASU_GRUPO,SESASU_ORDEN,');
SQL.Add('SESGRU_CODIGO,SESGRU_DESCRIP,SESGRU_MOSTRAR,');
SQL.Add('(CASE WHEN SESGRU_MOSTRAR = 1 THEN SEASU_ASUNTO ELSE SESGRU_DESCRIP) as ASUNTO ');
SQL.Add('from SES'+Part+'ASU A inner join SES'+Part+'GRU on SESGRU_CODIGO=A.SESASU_GRUPO ');
SQL.Add('where SESASU_SESION='+#39+inttostr(SesCodigo)+#39);
SQL.Add(' order by SESASU_GRUPO,SESASU_ORDEN');
Open;
end;
|
|
#4
|
||||
|
||||
|
Hola.
Creo que tienes que finalizar el CASE con un END. O sea : Código:
with QueryAsu do
begin
SQL.Clear;
SQL.Add('select SESASU_CODIGO,SESASU_GRUPO,SESASU_ORDEN,');
SQL.Add('SESGRU_CODIGO,SESGRU_DESCRIP,SESGRU_MOSTRAR,');
SQL.Add('(CASE WHEN SESGRU_MOSTRAR = 1 THEN SEASU_ASUNTO ELSE SESGRU_DESCRIP END) as ASUNTO ');
SQL.Add('from SES'+Part+'ASU A inner join SES'+Part+'GRU on SESGRU_CODIGO=A.SESASU_GRUPO ');
SQL.Add('where SESASU_SESION='+#39+inttostr(SesCodigo)+#39);
SQL.Add(' order by SESASU_GRUPO,SESASU_ORDEN');
Open;
end;
__________________
Marc Guillot (Hi ha 10 tipus de persones, els que saben binari i els que no). |
|
#5
|
||||
|
||||
|
Faltaba el case, pero ahora me da:
Código:
Datatypes are not comparable in expression CASE |
|
#6
|
||||
|
||||
|
Hola.
¿ SEASU_ASUNTO y SESGRU_DESCRIP són del mismo tipo ?. En caso de ser de tamaño distinto, deberias forzar el mismo tamaño con un CAST. Ejplo. cast(SEASU_ASUNTO as varchar(100)) Saludos.
__________________
Marc Guillot (Hi ha 10 tipus de persones, els que saben binari i els que no). |
|
#7
|
||||
|
||||
|
he probado a hacer el cast que me propones y el siguiente:
Código:
(CASE WHEN SESGRU_MOSTRAR = 1 THEN SESASU_ASUNTO ELSE cast(SESGRU_DESCRIP as blob) END) 1.000.000 de gracias. |
![]() |
|
|
|