郁闷的存储过程时间问题!!!大力等高手请进啊

thinhorse2004 2003-07-25 03:31:38
我想连续计算30天的数据,存储过程代码如下。
declare @ttt int
set @ttt=0

declare @date datetime
set @date=@tdate

while(@ttt<30) --计算30天
BEGIN
set @ttt=@ttt+1
INSERT #jxcrb_kc EXEC CH_JXCRB_KC_TZ1 @date1=@date,@date2=@date
set @date=dateadd(day,1,@date) --下一天
END

可是结果出来只有28、29、30三天或者二天的时间,好奇怪,大侠帮我解惑啊!
多谢!
...全文
28 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
thinhorse2004 2003-07-25
  • 打赏
  • 举报
回复
好吧。谢谢
jhselectonly@sina.com.cn
shmyfree 2003-07-25
  • 打赏
  • 举报
回复
我告诉你吧,告诉我你的电子信箱。
ok
thinhorse2004 2003-07-25
  • 打赏
  • 举报
回复
其中#jxcrb_kc1过程如下;

CREATE TABLE #jxcrb_kc1(
sdbh int,
qsrq datetime,
jsrq datetime,
txm varchar(16),
jj numeric(18,2),
sj numeric(18,2),
qckc numeric(18,2),
qmkc numeric(18,2),
rksl numeric(18,2),
drsl numeric(18,2),
dcsl numeric(18,2),
thsl numeric(18,2),
bfsl numeric(18,2),
sysl numeric(18,2),
dbsl numeric(18,2),
xssl numeric(18,2)
)

INSERT INTO #jxcrb_kc1(sdbh , qsrq , jsrq , txm , jj , sj , qckc , qmkc , rksl , drsl , dcsl , thsl , bfsl , sysl , dbsl , xssl )
SELECT DISTINCT c.sdbh, @date1, @date2 , b.txm , b.jhdj , b.csdj , 0.00 , 0.00 , 0.00 , 0.00 , 0.00 , 0.00 ,0.00 ,0.00 ,0.00 ,0.00
FROM t_ck_spbm b ,
t_ck_sdb c
WHERE b.zhsp_sdbh = c.sdbh

......
UPDATE #jxcrb_kc1
SET rksl = b.sl
FROM #jxcrb_kc1 a ,
(SELECT txm , sum(isnull(sl,0.00)) sl
FROM t_cs_zpgl_mxd c ,
t_cs_zpgl d
WHERE c.zpdh = d.zpdh
AND c.fdbh = d.fdbh
AND d.djlx = 1
AND d.czrq between @date1 and @date2
AND c.txm in( SELECT txm from #jxcrb_kc1)
GROUP BY txm ) b
WHERE a.txm = b.txm
......

SELECT a.sdbh , a.qsrq ,a.jsrq , a.txm , a.jj , a.sj , a.qckc, a.qmkc, a.rksl , a.drsl , a.dcsl , a.thsl , a.bfsl , a.sysl , a.dbsl , a.xssl
FROM #jxcrb_kc1 a
ORDER BY a.sdbh

DROP TABLE #jxcrb_kc1

GO
大家帮我看看吧,小弟搞了好久还是不太清楚怎么错了
谢谢:)


thinhorse2004 2003-07-25
  • 打赏
  • 举报
回复
CH_JXCRB_KC_TZ1是一个另外一个存储过程,计算该天的数据
参数date1和date2,在这里取得是同一天时间

把取到的数据放在#jxcrb_kc里面,这样子,本来应该有30天的数据,可是我执行
之后只有几天数据,好迷惑
高手指教指教!
nboys 2003-07-25
  • 打赏
  • 举报
回复
应该是EXEC CH_JXCRB_KC_TZ1有错

create proc test12
@tdate datetime
as
declare @ttt int
set @ttt=0
create table #jxcrb_kc (Date_col datetime)
declare @date datetime
set @date=@tdate
while(@ttt<30) --计算30天
BEGIN
set @ttt=@ttt+1
INSERT #jxcrb_kc values (@date)
set @date=dateadd(day,1,@date) --下一天
END
select * from #jxcrb_kc
drop table #jxcrb_kc

test12 '2003-7-25'

结果:
2003-07-25 00:00:00.000
2003-07-26 00:00:00.000
2003-07-27 00:00:00.000
2003-07-28 00:00:00.000
2003-07-29 00:00:00.000
2003-07-30 00:00:00.000
2003-07-31 00:00:00.000
2003-08-01 00:00:00.000
2003-08-02 00:00:00.000
2003-08-03 00:00:00.000
2003-08-04 00:00:00.000
2003-08-05 00:00:00.000
2003-08-06 00:00:00.000
2003-08-07 00:00:00.000
2003-08-08 00:00:00.000
2003-08-09 00:00:00.000
2003-08-10 00:00:00.000
2003-08-11 00:00:00.000
2003-08-12 00:00:00.000
2003-08-13 00:00:00.000
2003-08-14 00:00:00.000
2003-08-15 00:00:00.000
2003-08-16 00:00:00.000
2003-08-17 00:00:00.000
2003-08-18 00:00:00.000
2003-08-19 00:00:00.000
2003-08-20 00:00:00.000
2003-08-21 00:00:00.000
2003-08-22 00:00:00.000
2003-08-23 00:00:00.000
waitwater 2003-07-25
  • 打赏
  • 举报
回复
CH_JXCRB_KC_TZ1 是什么?
可能是 EXEC CH_JXCRB_KC_TZ1 @date1=@date,@date2=@date 的结果中只有三天或者二天的数据吧!
能不能把CH_JXCRB_KC_TZ1的内容贴出来!
thinhorse2004 2003-07-25
  • 打赏
  • 举报
回复
UP
高人们看过来啊!

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧