Select te um erro e nao acho

27/03/2013

1

Alguem sabe dizer o que pode ter de errado nesse select ou esta triplicando dados e naõ acho o problema.

SELECT R.RDB$FIELD_NAME AS Nome_Campo,

R.RDB$DESCRIPTION AS Descricao_Campo,

R.RDB$DEFAULT_VALUE AS Valor_Padrao_Campo,



CASE R.RDB$NULL_FLAG

WHEN 1 THEN 'SIM'

ELSE 'NÃO'

END AS Restricao_NotNull_Campo,



F.RDB$FIELD_LENGTH AS Tamanho_Campo,

F.RDB$FIELD_PRECISION AS Precisao_Campo,

F.RDB$FIELD_SCALE AS Escala_Campo,



CASE F.RDB$FIELD_TYPE

WHEN 7 THEN 'SMALLINT'

WHEN 8 THEN 'INTEGER'

WHEN 9 THEN 'QUAD'

WHEN 10 THEN 'FLOAT'

WHEN 11 THEN 'D_FLOAT'

WHEN 12 THEN 'DATE'

WHEN 13 THEN 'TIME'

WHEN 14 THEN 'CHAR'

WHEN 16 THEN 'INT64'

WHEN 27 THEN 'DOUBLE'

WHEN 35 THEN 'TIMESTAMP'

WHEN 37 THEN 'VARCHAR'

WHEN 40 THEN 'CSTRING'

WHEN 261 THEN 'BLOB'

ELSE 'UNKNOWN'

END AS Tipo_Campo,



F.RDB$FIELD_SUB_TYPE AS SubTipo_Campo,

CSET.RDB$CHARACTER_SET_NAME AS CHARSET_Campo

FROM RDB$RELATION_FIELDS R

LEFT JOIN RDB$FIELDS F ON R.RDB$FIELD_SOURCE = F.RDB$FIELD_NAME

LEFT JOIN RDB$COLLATIONS COLL ON F.RDB$COLLATION_ID = COLL.RDB$COLLATION_ID

LEFT JOIN RDB$CHARACTER_SETS CSET ON F.RDB$CHARACTER_SET_ID = CSET.RDB$CHARACTER_SET_ID

WHERE R.RDB$RELATION_NAME = :wtabela

ORDER BY R.RDB$FIELD_POSITION;
Responder

Posts

27/03/2013

Rafael Cunha

Veja se desse jeito resolve o seu problema.

SELECT DISTINCT R.RDB$FIELD_NAME AS Nome_Campo,
       R.RDB$DESCRIPTION AS Descricao_Campo,
       R.RDB$DEFAULT_VALUE AS Valor_Padrao_Campo,
       CASE R.RDB$NULL_FLAG
        WHEN 1 THEN 'SIM'
        ELSE 'NAO'
       END AS Restricao_NotNull_Campo,
       F.RDB$FIELD_LENGTH AS Tamanho_Campo,
       F.RDB$FIELD_PRECISION AS Precisao_Campo,
       F.RDB$FIELD_SCALE AS Escala_Campo,
       CASE F.RDB$FIELD_TYPE
        WHEN 7 THEN 'SMALLINT'
        WHEN 8 THEN 'INTEGER'
        WHEN 9 THEN 'QUAD'
        WHEN 10 THEN 'FLOAT'
        WHEN 11 THEN 'D_FLOAT'
        WHEN 12 THEN 'DATE'
        WHEN 13 THEN 'TIME'
        WHEN 14 THEN 'CHAR'
        WHEN 16 THEN 'INT64'
        WHEN 27 THEN 'DOUBLE'
        WHEN 35 THEN 'TIMESTAMP'
        WHEN 37 THEN 'VARCHAR'
        WHEN 40 THEN 'CSTRING'
        WHEN 261 THEN 'BLOB'
        ELSE 'UNKNOWN'
       END AS Tipo_Campo,
       F.RDB$FIELD_SUB_TYPE AS SubTipo_Campo,
       CSET.RDB$CHARACTER_SET_NAME AS CHARSET_Campo
FROM RDB$RELATION_FIELDS R
LEFT JOIN RDB$FIELDS F ON R.RDB$FIELD_SOURCE = F.RDB$FIELD_NAME
LEFT JOIN RDB$COLLATIONS COLL ON F.RDB$COLLATION_ID = COLL.RDB$COLLATION_ID
LEFT JOIN RDB$CHARACTER_SETS CSET ON F.RDB$CHARACTER_SET_ID = CSET.RDB$CHARACTER_SET_ID
WHERE R.RDB$RELATION_NAME = :wtabela
ORDER BY R.RDB$FIELD_POSITION;
Responder

27/03/2013

Wilton Júnior

resolveu muito obrigado.
Responder

27/03/2013

Joel Rodrigues

Estou encerrando o tópico.
Responder