With SQL query adding extra column that does not exist in table

Asked

Viewed 167 times

1

You can see that the countryside ORCAMENTO.DATA_VENDA, is duplicated isn’t it? Well, I don’t know how to make it more precise than the field ORCAMENTO.DATA_VENDA, come as null(As if I deleted the values of the column that is repeated) .

Below is how Sql is in the system

SELECT
  ORCAMENTO.ID AS CODIGO,
  ORCAMENTO.DATA_VENDA AS DATA_ORCAMENTO,
  ORCAMENTO.DATA_VENDA,
  ORCAMENTO.VALOR_FINAL
FROM ORCAMENTO
  LEFT JOIN CLIENTES ON (ORCAMENTO.NOME_CLIENTE = CLIENTES.CLIENTE)   
  LEFT JOIN VENDEDOR ON (ORCAMENTO.ID_VENDEDOR  = VENDEDOR.ID)
WHERE
  ORCAMENTO.SITUACAO = 'IMPORTADO'

The result of it currently comes like this:
inserir a descrição da imagem aqui

I need my appointment to go something like this:
inserir a descrição da imagem aqui

  • You can do it?
  • How would it be?

Monde the Question Title for better understanding.

  • What does "two equal fields being one of them null" mean? If one of them is null then it will never be equal to another field, even if the content of the other is null. If you want to test whether the contents of a field are NULL use: ... campo IS NULL .... Note the fact that your DATA_VENDA field is not duplicated, only the content of the listed lines is NULL.

  • I see that you have not read or if you want to visualize what I am asking... if you check what is in msg understand what I want. be less literal and more rational.

  • the image is just an illustration of how I want it to stay is not real with the least knowledge would know just seeing the above query.

  • so it is very easy to come out negative all kind of question just by the title without analyzing the content of the question.

  • I’m not the one who denied your question, I just commented that maybe you don’t understand the meaning of NULL.

  • this doesn’t make any sense, if the data_sale field has to be null it shouldn’t be the same field that is in the table. just do ... data_venda as data_orcamento, null as data_venda .... using his words "with the least amount of knowledge you would know"

  • What I need is to clear the copy of the field to be null

  • 1

    the code I put up, do it.

  • The field of sale doesn’t have to be I’m just added a column more.

  • then just do what I said and add a column like null... SELECT
 ORCAMENTO.ID AS CODIGO,
 ORCAMENTO.DATA_VENDA AS DATA_ORCAMENTO,
 NULL AS DATA_VENDA,
 ORCAMENTO.VALOR_FINAL
FROM ORCAMENTO
 LEFT JOIN CLIENTES ON (ORCAMENTO.NOME_CLIENTE = CLIENTES.CLIENTE) 
 LEFT JOIN VENDEDOR ON (ORCAMENTO.ID_VENDEDOR = VENDEDOR.ID)
WHERE
 ORCAMENTO.SITUACAO = 'IMPORTADO' this is the only option for what you are wanting, if it is not that try to understand and explain better what you are wanting.

  • not everything in life It makes sense, what matters is the end result. and with respect to the knowledge that I have spoken above the minimum of knowledgeable to understand what is being proposed. if I had known how to do this I would not have asked.

  • Anyway helped me and very much. Thank you very much.

  • could rewrite your question as "bring two equal but different fields" and that doesn’t make any sense. Here we only have the information posted in the question and goodwill of many people wanting to help, and you "charged" the minimum of knowledge to interpret your question which was quite rude. On the solution, have.

Show 8 more comments

2 answers

3


SELECT
  ORCAMENTO.ID AS CODIGO,
  ORCAMENTO.DATA_VENDA AS DATA_ORCAMENTO,
  NULL AS DATA_VENDA,
  ORCAMENTO.VALOR_FINAL
FROM ORCAMENTO
  LEFT JOIN CLIENTES ON (ORCAMENTO.NOME_CLIENTE = CLIENTES.CLIENTE)   
  LEFT JOIN VENDEDOR ON (ORCAMENTO.ID_VENDEDOR  = VENDEDOR.ID)
WHERE
  ORCAMENTO.SITUACAO = 'IMPORTADO'

3

Oops! See well you can put so in your query

SELECT
  ORCAMENTO.ID AS CODIGO,
  ORCAMENTO.DATA_VENDA AS DATA_ORCAMENTO,
  CAST(NULL AS TIMESTAMP) AS DATA_VENDA,
  ORCAMENTO.VALOR_FINAL
FROM ORCAMENTO
  LEFT JOIN CLIENTES ON (ORCAMENTO.NOME_CLIENTE = CLIENTES.CLIENTE)   
  LEFT JOIN VENDEDOR ON (ORCAMENTO.ID_VENDEDOR  = VENDEDOR.ID)
WHERE
  ORCAMENTO.SITUACAO = 'IMPORTADO'

If you need your capo to have the same kind of column you’re duplicating, you can create your virtual column of the type you want.
CAST converts an expression to the desired data type. If conversion is not possible, an error will be generated.

Browser other questions tagged

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