SQL查询结果相加减

create procedure caigouzhouqi
(
@PorStartDate datetime=null,
@PorEndDate datetime=null
)
AS
SET NOCOUNT ON;
if @PorStartDate is null
begin
set @PorStartDate =''
end
if @PorStartDate is null
begin
set @PorEndDate =''
end

declare @dateqj datetime
declare @dateck datetime
set @dateqj=null
set @dateck=null
--CONVERT(varchar(12) , se.FDate, 111 )

select CONVERT (varchar(12), p.fdate,111) 采购日期 ,
t.fnumber 物料代码,
t.fmodel 规格型号,
t.fname 物料名称,
p.FBillNo 采购单号,
CONVERT(varchar(12),i.FDate,111) 入库日期, --i.FDate 入库日期,
i.FBillNo 入库单号,
CONVERT(varchar(12),p2.FDate,111)请检单日期, --p2.FDate 请检单日期,
p2.FBillNo 请检单单号

from poorder p
inner join poorderentry p1 on p.finterid=p1.finterid --采购订单
inner join t_ICItem t on t.fitemid=p1.fitemid --物料
inner join POInStockEntry p3 on p3.FOrderInterID=p.FInterID and p3.FSourceTranType = 71 and p3.FSourceEntryID = p1.FEntryID
inner join POInstock p2 on p2.FInterID=p3.FInterID
inner join ICStockBillEntry ie on ie.FSourceTranType = 72 and ie.FSourceInterId = p2.FInterID and ie.FSourceEntryID = p3.FEntryID --收料通知请检单
inner join icstockbill i on i.FInterID =ie.FInterID and i.FTranType = 1 --外购入库单
where p.FDate between @PorStartDate and @PorEndDate

上面的代码是我写的存储过程,我需要整个表查询出来的结果多显示两个列,一列的结果是P2.FDATE减去p.fdate,另外一列的结果是 i.fdate减P.FDATE,,不会写了 谢谢高手帮忙!

第1个回答  2014-12-12
相减 你是需要得到两个日期相差的天数,还是小时数,还是其他的? 有datediff函数的,你可以先看一下
相似回答