日期:2014-05-18  浏览次数:20753 次

为什么存储过程执行后,没有得到想要结果.急!!!!!!!!!不够再加分
在前台执行后,没有往数据库表hcost2hisdata..H_VoucherCost   里插入数据.
如果把busdate=@cdate   改成一个具体日期(如busdate   between   '2007.03.01 '   and   '2007.03.29 ')就可以.
但是前台有日期选择的,请问这个是什么原因超成的.

SET   QUOTED_IDENTIFIER   ON  
GO
SET   ANSI_NULLS   ON  
GO


ALTER                                                             PROCEDURE   sp_import_voucher_cost
@cdate   char(10)
AS

--   初始化
DELETE   hcost2hisdata..H_VoucherCost   WHERE   BusDate   =   @cdate

INSERT   INTO   hcost2hisdata..H_VoucherCost  
(BusDate,DeptCode,VoucherNo,Abstract,CostCatCode,Money)
SELECT   a.docDate,h.ut_no,a.docID,e.certName,i.costcatcode,b.docJM
FROM   hsdata..tb_doc   a  
INNER   JOIN       hsdata..tb_docmemo   b   ON   a.docUID   =   b.docUID  
INNER   JOIN     hsdata..tb_certsum   e     ON   b.certID   =   e.certID  
INNER   JOIN     hsdata..tb_acndict   f     ON   b.acnID   =   f.acnID  
INNER   JOIN     hsdata..utcode   h             ON   a.docDpt   =   h.ut_id  
INNER   JOIN     t_acntsubject   i     ON     f.acncode   =   i.itemcode
INNER   JOIN     hsdata..tb_cert     j   on   a.certuid=j.certuid
where   a.docstaff!=0         and   b.docJM!=0
and   (i.costcatcode!= ' '   and   i.costcatcode   is   not   null)
and   i.costcatcode   not   in( 'D01 ', 'D02 ', 'D03 ', 'E0301 ', 'E0302 ', 'F0102 ', 'E08 ')
and       a.docodate=@cdate


GO
SET   QUOTED_IDENTIFIER   OFF  
GO
SET   ANSI_NULLS   ON  
GO



------解决方案--------------------
把日期型都转为一样的格式试试

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


ALTER PROCEDURE sp_import_voucher_cost
@cdate char(10)
AS

-- 初始化
DELETE hcost2hisdata..H_VoucherCost WHERE convert(char(10),BusDate,120) = convert(char(10),@cdate,120)

INSERT INTO hcost2hisdata..H_VoucherCost
(BusDate,DeptCode,VoucherNo,Abstract,CostCatCode,Money)
SELECT a.docDate,h.ut_no,a.docID,e.certName,i.costcatcode,b.docJM
FROM hsdata..tb_doc a
INNER JOIN hsdata..tb_docmemo b ON a.docUID = b.docUID
INNER JOIN hsdata..tb_certsum e ON b.certID = e.certID
INNER JOIN hsdata..tb_acndict f ON b.acnID = f.acnID
INNER JOIN hsdata..utcode h ON a.docDpt = h.ut_id
INNER JOIN t_acntsubject i ON f.acncode = i.itemcode
INNER JOIN hsdata..tb_cert j on a.certuid=j.certuid
where a.docstaff!=0 and b.docJM!=0
and (i.costcatcode!= ' ' and i.costcatcode is not null)
and i.costcatcode not in( 'D01 ', 'D02 ', 'D03 ', 'E0301 ', 'E0302 ', 'F0102 ', 'E08 ')
and convert(char(10),a.docodate,120)=convert(char(10),@cdate,120)


GO
SET QUOTED_IDENTIFIER OFF
GO
S