Bineesh  Viswanath

Bineesh Viswanath

  • NA
  • 1k
  • 760.2k

Need help to Divide two columns in SQL Server

May 11 2016 7:56 AM
Sir,
I need your help to create a sql query to divide two columns(rate,qty) and set the query result into a single row.
suppose my rate is 35000 and qty=5 I should get 7000.
Here I writing my sql query
select distinct
invopstock.opstock,
invopstock.rate,
invopstock.pid,
invpurchaseitems.pid AS PURCHASEPID,
invpurchaseitems.rate as PRATE,
sum(invpurchaseitems.amount/invpurchaseitems.qty) AS PURCHASEAMOUNT ,
invpurchaseitems.freeqty from invopstock,invpurchaseitems
where invopstock.pid=invpurchaseitems.pid and invopstock.pid=21
and invopstock.COMPCODE = 'MNA' AND invopstock.DIVCODE = 'DIV' AND INVOPSTOCK.OPSTOCK>0
and invpurchaseitems.isdeleted=0
group by
invopstock.opstock,
invopstock.rate,
invopstock.pid,
invpurchaseitems.pid,
invpurchaseitems.rate,
invpurchaseitems.freeqty

Answers (1)