I have a two tables regarding my question. Table 1, say INDEX, stores metadata on statements. Table 2, say DEFINITION, defines what type of record is in INDEX.
There is a column in table INDEX where the metadata, say METADATA, is stored. This column is a CHARACTER type. I need to write a query that will sort table INDEX by the METADATA column and have some sort of logic to parse the sort to an INTEGER when the related column, say TYPE, in DEFINITION is equal to 'I'.
Example desired sort when METADATA is defined as an 'I' type by column TYPE in table DEFINITION:
SELECT
*
FROM
INDEX INDEX,
DEFINITION DEFINITION
WHERE
DEFINITION.DEF_ID = INDEX.DEF_ID AND
DEFINITION.DEF_ID = 1
ORDER BY INTEGER(METADATA)
Example normal sort:
SELECT
*
FROM
INDEX INDEX,
DEFINITION DEFINITION
WHERE
DEFINITION.DEF_ID = INDEX.DEF_ID AND
DEFINITION.DEF_ID = 1
ORDER BY METADATA
Is there a way to add in the integer parsing of METADATA based on a related record in a different table? Would it be possible to inject the INTEGER( ) into the ORDER BY clause based on some sort of IF statement/logic?
(Note: This is the way our tables are designed, please don't suggest modifying the design as that is not a viable solution. Thank you.)
There is a column in table INDEX where the metadata, say METADATA, is stored. This column is a CHARACTER type. I need to write a query that will sort table INDEX by the METADATA column and have some sort of logic to parse the sort to an INTEGER when the related column, say TYPE, in DEFINITION is equal to 'I'.
Example desired sort when METADATA is defined as an 'I' type by column TYPE in table DEFINITION:
SELECT
*
FROM
INDEX INDEX,
DEFINITION DEFINITION
WHERE
DEFINITION.DEF_ID = INDEX.DEF_ID AND
DEFINITION.DEF_ID = 1
ORDER BY INTEGER(METADATA)
Example normal sort:
SELECT
*
FROM
INDEX INDEX,
DEFINITION DEFINITION
WHERE
DEFINITION.DEF_ID = INDEX.DEF_ID AND
DEFINITION.DEF_ID = 1
ORDER BY METADATA
Is there a way to add in the integer parsing of METADATA based on a related record in a different table? Would it be possible to inject the INTEGER( ) into the ORDER BY clause based on some sort of IF statement/logic?
(Note: This is the way our tables are designed, please don't suggest modifying the design as that is not a viable solution. Thank you.)