How to pull a data from the same field?

0

Personally, I know that my question may be silly ... But how can I pull data from a field only in SQL. Is that actually I'm putting together a report of the company's products ... There are products that drive it's value '1' but it when it's sold in Cash For example, it becomes '0.98', understand? I wanted to do a following, There is a product that Unit is worth '1' and it being sold per box is also worth '1', so I ignore ... But there is a product that the value of the unit is '1' sold in 'PT' or 'CX' (depending on the product) its value drops to '0.98' so I get this product 0.98 + Unit values that is '1' and if you have more sales unit like PT or DP package and display) picks up everything too, understand? I've done something more complex than that, but my head totally bugged, since yesterday thinking and nothing. thank you. My code looks like this:

SELECT produto.cd_prod, produto.descricao, unid_prod.qtde_unid, unid_prod.fator_preco, unid_vda FROM produto, unid_prod WHERE unid_prod.cd_prod = produto.cd_prod AND unid_prod.fator_preco = '0.9800'

But in this case the query only pulls 0.9800 and ignores the rest of the Sales Units and I wanted it to be 0.9800 so it would bring the other units together. I'm new here, but thank you in advance.

    
asked by anonymous 12.12.2017 / 13:54

2 answers

0

If fator_preco is of type VARCHAR use:

SELECT fator_preco FROM Tabela WHERE fator_preco LIKE '0.9800%';

0.9800% means you want strings beginning with 0.9800, % let's say "remaining."

Now if fator_preco is of type DECIMAL, I would do so:

SELECT fator_preco FROM Tabela  WHERE CAST(fator_preco AS CHAR) LIKE '0.9800%'

In this case you are using the LIKE as in the other example, however making a CAST in the value, converting from DECIMAL to VARCHAR.

I tested it here and it worked perfectly, any questions just comment!

    
12.12.2017 / 14:20
0

The ugly way would be to convert to string and make a like ... the correct way would be to multiply the value by 10000 and check if the integer part is 9800.

    
12.12.2017 / 14:18