How to pull a die from the same field?

Asked

Viewed 47 times

0

Come on, guys, I know my question might be silly... But how can I pull data from a field only in SQL. It’s just that I’m actually putting together a report of the company’s products... There are products that unit its value '1' but when it is sold in Box for example, becomes '0.98', understood? I wanted to do a following, It has a product that the unit is worth '1' and it being sold by box is also worth '1', so I ignore... But there is a product that the unit value of it is '1' but it sold in 'PT' or 'CX' (Depending on the product) the value of it goes down to '0.98' so I take this product 0.98 + the unit values that is '1' and if you have more sales unit as PT or DP (package and display) You take everything, too, you understand? I’ve done more complex things than that, but my head totally bugged, since yesterday thinking and nothing. Thank you. My Code is 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'

Only in this case the query only pulls 0.9800 and ignores the rest of the sales units and I wanted that if it was 0.9800 it would bring the other units of measure together. I am New here, but already thank you.

  • factor_preco is a decimal or varchar field?

  • Do you want to determine a search for the value of a field? If yes, you can return other fields besides the field sought?

2 answers

0

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

  • That is gambiarra

  • @Alexandro Carneiro It would be interesting to put the mounted query.

0


If fator_preco is of the VARCHAR use type:

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

0.9800% means you want strings that start with 0.9800, the % let’s say it means "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 LIKE as in the other example, but doing a CAST in the value, converting from DECIMAL to VARCHAR.

Already test here and it worked perfectly, any doubt just comment !

Browser other questions tagged

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