这语句该如何写:
temp1 
lj01,lj02,lj03,lj04,lj05.....ljN
我想把temp1的前15个字段插入temp2  表结构一样.....

解决方案 »

  1.   

    insert temp2 select * from temp1
      

  2.   

    insert temp2 select lj01,lj02,lj03......lj15 from temp1
      

  3.   

    insert into temp2(lj01,lj01,...[十五个字段名]...lj15)select lj01,lj02,..... from temp1
      

  4.   

    DECLARE @sql VARCHAR(8000)
    SET @sql = ''
    SELECT TOP(15)
    @sql = @sql + '[' + [Name] + '],'
    FROM SysColumns 
    WHERE id = OBJECT_ID('dbo.temp1')IF @sql <> ''
    BEGIN
    SET @sql = 'INSERT INTO temp2('+ SUBSTRING(@sql, 1, LEN(@sql)-1) +') SELECT ' + SUBSTRING(@sql, 1, LEN(@sql)-1) + ' FROM temp1'
    EXEC (@sql)
    END