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

插入相同记录问题(identity)
有2张表
A表中有3个字段   id     FirstClass   SecondClass  
              1           1                       01
                                2           1                       02
                                3           1                       03
(id为从B表中取得的MaxId值而不是自增字段,   FirstClass为大类编号,SecondClass为小类编号)

B表中有2个字段           MaxId       Name
    4               A

(MaxId存当前最大的id+1,以供下次加记录时使用,Name为表名)

现在想根据A表中这3条大类编号为1的相同记录插入到大类编号为2、3   里,也就是想得到以下结果
              id     FirstClass   SecondClass  
              1           1                       01
                                2           1                       02
                                3           1                       03
              4           2                       01
                                5           2                       02
                                6           2                       03
              7           3                       01
                                8           3                       02
                                9           3                       03

请高手帮忙给个SQL语句

------解决方案--------------------
是这样?
declare @ta table (id int, FirstClass int, SecondClass varchar(2))
insert @ta select 1, 1, '01 '
insert @ta select 2, 1, '02 '
insert @ta select 3, 1, '03 '

declare @a int,@b int,@i int,@j int,@s varchar(2)
select @a=isnull(max(firstclass),0)