各位大侠 帮帮忙 100分马上送!!!

xiaoduoliu 2003-07-28 10:12:07
我现在的问题是:
有一个表是卡号 表名:cardtab 字段有:acctid varchar(50),userid varchar(50),datereged varchar(20)
另外还有个表tab1 字段有:starttime varchar(50),acctid varchar(50),userid varchar(50),duration int
还有一个表tab 字段有:starttime varchar(50),duration int

需要做的是:
我要从表tab中找出starttime大于cardtab表中的最小的datereged的所有记录,
把cardtab表按照datereged的降序排列,循环的把表tab中满足条件的记录加上cardtab表中的acctid和userid,插入到表tab1中,再把cardtab表中的datereged的值改为starttime得值,如此往复循环,直到tab表中没有满足条件的记录。

谁能帮我做个存储过程,还有这个过程要求是每个5分钟执行一次。
拜托了 各位 马上结帖 给分!!
...全文
18 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
woyaofengle 2003-07-29
  • 打赏
  • 举报
回复
作业我不懂,可能象这样
USE msdb
EXEC sp_add_jobstep @job_name = 'checkcard',
@step_name = 'Set database to read only',
@subsystem = 'TSQL',
@command = 'exec sp_dboption ''sales'', ''read only'', ''true''',
@retry_attempts = 5,
@retry_interval = 5



create procedure checkcard
as
insert into tab1 select cardtab.acctid,cardtab.userid,startime as b from tab,cardtab where startime>(select min(datereged) from cardtab order by datereged )
update cardtab
set datereged=tab1.startime
where tab1.startime>(select min(datereged) from cardtab order by datereged )
waitwater 2003-07-29
  • 打赏
  • 举报
回复
现在按照acctid为主键做插入功能,
insert tab1
select cardtab.datereged,cardtab.duration,cardtab.acctid,cardtab.userid
from tab,cardtab
where tab.starttime<min(cardtab.datereged) and tab1.acctid=cardtab.acctid

以后建立JOB,可以达到每5分钟执行一次。你自己考虑怎么做才好吧!







愉快的登山者 2003-07-29
  • 打赏
  • 举报
回复
建立JOB,可以达到每5分钟执行一次。
CrazyFor 2003-07-29
  • 打赏
  • 举报
回复
把cardtab表按照datereged的降序排列,循环的把表tab中满足条件的记录加上cardtab表
--------------------------------------------------^^^^^^^^^这个条件是什么???
中的acctid和userid,
txlicenhe 2003-07-29
  • 打赏
  • 举报
回复
没那么多循环吧?
你先交代清楚,好象不太难。两条SQL语句应该可以搞定。
liuyun2003 2003-07-29
  • 打赏
  • 举报
回复
表cardtab和表tab使用什么关联?表tab1的主键是什么啊?是不是表cardtab中每条记录都要和表tab(符合选择条件的)中的数据组合一下,然后放到表tab1中啊。把这些关系说清楚一些。

22,207

社区成员

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

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