Field alias in oracle Where clause

Asked

Viewed 590 times

2

I have a Decode in my select so:

.....
DECODE(MAT.IND_TIPO_MAT_MED,
           '1', 'BRASINDICE',
           '2', 'SIMPRO',
           '9', 'TABELAPROPRIA') TIPOTABELA,
.....

I need to pass these values on the clause where, for they come by querystring, and in the querystring I take these values: BRASINDICE,SIMPRO or TABELAPROPRIA. Turns out, how TIPOTABELA is an alias, in the clause Where en can’t catch them. If I take the name of the real field, I don’t have those values, but just: 1,2 or 9, and in the querystring are passed the values represented and my query will not return anything. I need to do an inversion in the query, ie, receive by querystring the values and time to move to the clause where, pass the real values. How do I do this?

Note: Via querystring I receive: BRASINDICE,SIMPRO or TABELAPROPRIA and the field accepts:1,2 or 9. There is how to make a reversal?

I made a case and found half Gambi. I did so:

if(tipoTabela != string.Empty)
            {
                switch(tipoTabela)
                {
                    case "BRASINDICE":
                        tipoTabela = "1";
                        break;

                    case "SIMPRO":
                    tipoTabela = "2";
                    break;

                    case "TABELAPROPRIA":
                    tipoTabela = "9";
                    break;

                    default:
                    tipoTabela = string.Empty;
                    break;

                }
  • This second part of your question no longer corresponds to the subject (Sql, Oracle). In this case, ask another question by adding the appropriate tag (c#, java, whatever). Blz?

1 answer

1

What you can do is use a sub-select and then apply the filter:

SELECT * FROM
(
    .....
    DECODE(MAT.IND_TIPO_MAT_MED,
               '1', 'BRASINDICE',
               '2', 'SIMPRO',
               '9', 'TABELAPROPRIA') TIPOTABELA,
    .....
) AS TBL_CONSULTA
WHERE TIPOTABELA LIKE 'SIMPRO'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.