用游标插入数据问题:有两张表,
q_enter 记录某个用户对应的快捷操作方式,
字段有
id,account,show_index
1    A01       1   
2    A01       2
3    A01       3
4    A02       1
5    A02       2   
6    A02       3 相关联的另一个表
u_enter 与上表的ID关联,记录快捷名称
id   name
1     KJ1
2     KJ2
3     KJ3   
4     KJ1
5     KJ2
6     KJ3现在如何用SQL语句,最好是游标的方式,向每个用户都能实现增加3个新快捷方式(KJ4,KJ5,KJ6)?
大哥大姐们,帮帮忙!O(∩_∩)O谢谢!
在线等…………

解决方案 »

  1.   


    declare @q_enter table (id int,account varchar(3),show_index int)
    insert into @q_enter
    select 1,'A01',1 union all
    select 2,'A01',2 union all
    select 3,'A01',3 union all
    select 4,'A02',1 union all
    select 5,'A02',2 union all
    select 6,'A02',3declare @u_enter table (id int,name varchar(3))
    insert into @u_enter
    select 1,'KJ1' union all
    select 2,'KJ2' union all
    select 3,'KJ3' union all
    select 4,'KJ1' union all
    select 5,'KJ2' union all
    select 6,'KJ3'insert into @u_enter
    select a.id,b.name from @q_enter a
    cross join 
    (select 'KJ4' as name union select 'KJ5' union select 'KJ6') bselect * from @u_enter order by id,name
    /*
    id          name
    ----------- ----
    1           KJ1
    1           KJ4
    1           KJ5
    1           KJ6
    2           KJ2
    2           KJ4
    2           KJ5
    2           KJ6
    3           KJ3
    3           KJ4
    3           KJ5
    3           KJ6
    4           KJ1
    4           KJ4
    4           KJ5
    4           KJ6
    5           KJ2
    5           KJ4
    5           KJ5
    5           KJ6
    6           KJ3
    6           KJ4
    6           KJ5
    6           KJ6
    */游标的效率太差了,这样就可以了。
      

  2.   

    @q_enter 中的id和@u_enter是对应的,这样出来的 @u_enter id是重复的,那每个用户的快捷名称也是重复的呀