表结构
用户流水表:
id userid   orderdtime disordertime
1    13     2006-12-14  1900-00-00
2    14     2006-12-28  1900-00-00
3    13     1900-00-00  2006-12-28要实现的功能是 把用户流水表里的记录插入用户状态表 并且判断用户的状态 先比较是否有这个用户 没有这个用户则插入一条新记录 如果用户为order状态 则将状态字段status置0 如果用户已经退订了 即disordertime 有值 则 status置1 并更新已经存在的记录如 这是按我的思路生成的用户状态表
用户状态表
id userid   orderdtime disordertime status
1  13       2006-12-14  2006-12-28     1
2  14       2006-12-28  1900-00-00     0求这个存储过程

解决方案 »

  1.   

    如果用户为order状态
    ========================
    order状态指什么?
      

  2.   

    create proc test_f
    as
    begin
    update b
    set status=1
     from 用户流水表 a inner join  用户状态表 b on a.userid=b.userid and a.id=b.id
    where status=0
    insert 用户状态表select *,0 from 用户流水表 b
    where not exists(select 1 from 用户状态表 where userid=b.userid and a.id=b.id)
    end
    --测试
    exec test_f
      

  3.   

    如果用户为order状态
    ========================
    order状态指什么?
    指的是有定制时间的 即ordertime有大于1900-00-00的值
      

  4.   

    roy_88(论坛新星_燃烧你的激情!!
    谢谢 我先试试
      

  5.   


    不行啊 这是生成的句子 没有任何数据插入Bset ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go
    ALTER proc [dbo].[userstatus_pro]
    as
    begin
    update b
    set status=1
     from a inner join  b on a.userid=b.userid and a.id=b.id
    where status=0
    insert bselect *,0 from a
    where not exists(select 1 from b where userid=b.userid and a.id=b.id)
    end