--表中同类型相减
--查询无出库
select 产品名称=pname,单价=prc,库存数量=ct from input where flag=1 and
pname+convert(varchar(25),prc) not in(select pname+convert(varchar(25),prc) from input where flag=0)
union
--查询有出库
select 产品名称=a.pname,单价=a.prc,库存数量=a.库存数量-b.库存数量 from
(select pname,ct,库存数量=sum(ct),prc from dbo.input where flag=1 group by pname,prc,ct) a,
(select pname,ct,库存数量=sum(ct),prc from dbo.input where flag=0 group by pname,prc,ct) b
where a.prc=b.prc and a.pname=b.pname
--查询起始0点至结束23:59
sql = string.Format("Select 入库单位,产品名称,规格,单位,数量,单价,合计=(数量*单价),时间,备注,操作人 from vinput where 时间 between '{0}' and '{1}' and 标志=1", dateTimePicker1.Value.ToShortDateString() + " 00:00", dateTimePicker2.Value.ToShortDateString() + " 23:59");