Forums - C# Corner

Forum guidelines
Apurva Apurva

Apurva Apurva

  • 1.6k
  • 108
  • 6.8k

sum subtract in sql server

Jul 11 2018 7:46 AM
I have a  a select commamd 
select sd.section_id,Bm.Art,Color,sec.fld_barcode,sec.fld_sectionname,pro_barcode,sd.size,sum(sd.pro_Inqty)-Sum(sd.pro_outqty)as StockInhand from stock_trans_master sm
join stock_trans_details sd
on sm.st_id=sd.st_id
join BarcodeMaster Bm
on Bm.Barcode_m=sd.pro_barcode
join tbl_sectionmaster sec
on sd.section_id=sec.fld_id
where voucherdate <= '11-07-2018 00:00:00'
and (pro_barcode like ''+'%' )
AND (Color like 'S.GREEN' )
(Bm.size like '4' )
(Art like 'AUTUMN' )
group by sd.section_id,Bm.Art,sd.size,sec.fld_barcode,sec.fld_sectionname,pro_barcode,Color
 This statement return now  all data which stockinhand in equal to 0 value
now i want (sd.pro_Inqty)-Sum(sd.pro_outqty)as StockInhand is always return greater than 0 value.
Please suggest me.

Answers (4)