eg:
INSERT INTO Users
    (St_ID, Us_User, Us_Password, Us_Term, Us_State, Us_Group, Ex_Receipt)
select '5817', '04105817', 'x', '2004-2-28', 'Enable', 'abc', '7'
union all
select '5818', '04105818', 'x', '2004-2-28', 'Enable', 'abc', '8'
union all
select '5819', '04105819', 'x', '2004-2-28', 'Enable', 'abc', '9'

解决方案 »

  1.   

    select top 10 identity(int,1,1) as newid into # from sysobjectsinsert into users
    select St_ID+newid , '0'+ cast(cast(Us_User as int)+newid as varchar(10)), Us_Password, Us_Term, Us_State, Us_Group, Ex_Receipt
    from users ,#
      

  2.   

    最好使用循环让  St_ID, Us_User,Ex_Receipt 的值递增 假如我要插入10000条记录,咋办?
      

  3.   

    最好使用循环让  St_ID, Us_User,Ex_Receipt 的值递增 I
    St_ID, Us_User,Ex_Receipt 应都为INT
    NSERT INTO Users
        (St_ID, Us_User, Us_Password, Us_Term, Us_State, Us_Group, Ex_Receipt)
    select IDENTITY(smallint, (select max(St_id) from users)+1, 1) AS St_id, IDENTITY(smallint, (select max(St_id) from users)+1, 1) AS Us_User, 'x', '2004-2-28', 'Enable', 'abc', '7'
    union all
    select IDENTITY(smallint, (select max(St_id) from users)+1, 1) AS St_id, IDENTITY(smallint, (select max(St_id) from users)+1, 1) AS Us_User, 'x', '2004-2-28', 'Enable', 'abc', '8'