Convert the result value of the sql query

Asked

Viewed 807 times

0

I have the query that return me two results where I would like to format it to came in the proper format. How could I do this?

select *, sum(valor) as ValorSoma, count(pedido) as QtdPedido from tb_vendas
where idvendas > 0
and data_venda between '05/10/2015' and '11/04/2016'
and vendedor = ''
group by cliente 
order by QtdPedido desc

Decimal type sum value

Qtdpedido type integer

Thanks

  • Let me get this straight, you’re using this query somewhere in your system ? and want to store a two variables one of decimal type other of whole type ? or has nothing to do with ?

  • The result of Valuemote is Qtdpedido comes as a string

  • You want what format?

1 answer

0

If you want the result to be of the numeric type, it is necessary to make a CAST or CONVERT. With you did not specify which DBMS, I took the liberty to exemplify in SQL Server:


select 
  *, 
  CAST(sum(valor) AS NUMERIC(10,2)) as ValorSoma, 
  CAST(count(pedido) AS INTEGER) as QtdPedido 
from tb_vendas
where 
  idvendas > 0
  and data_venda between '05/10/2015' and '11/04/2016'
  and vendedor = ''
group by cliente 
order by QtdPedido desc

The above example returns the Valuemote field with type Numeric and Qtdpedido with type Integer.

Browser other questions tagged

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