declare @tablename varchar(30)
set @tablename = 'kc19991111'
update yourtable set id = left(id, len(id) - 8) + right(@tablename, 8)

解决方案 »

  1.   

    insert 新表 
    select right(name,8) from sysobjects where xtype='u' and name like 'kc%'
      

  2.   

    select right(name,8) as 表名 into 新表 from sysobjects where xtype='u' and name like 'kc%'
      

  3.   

    create procedure GetTableName
    @PartOfTableName as char(8)
    as
    Declare @name as Varchar(50)
    DECLARE myCursor CURSOR FOR select name from dbo.sysobjects where type='U' and right(name,8)=@PartOfTableName
    OPEN myCursor
    FETCH NEXT FROM myCursor INTO @name
    WHILE  @@FETCH_STATUS=0
    BEGIN
    UPDATE Table1 SET Column1=@name WHERE CURRENT OF myCursor
    FETCH NEXT FROM myCursor INTO @name
    END
    CLOSE myCursor
    DEALLOCATE myCursor
      

  4.   

    表名已经抽出来了,不过又碰到一个问题,怎么将字段内容作为表名,提供给select... from...
    方便从里面抽取数据。正在等待回复,大力请帮忙!
      

  5.   

    如:
    declare @表名变量 varchar(100)select @表名变量=name from 表 where 编号=1exec('select * from '+@表名变量)
      

  6.   

    declare @表名变量 varchar(100)select @表名变量=name from 表 where 编号=1exec('select * from kc'+cast(@表名变量 as varchar(10))
      

  7.   

    exec('select * from kc'+cast(@表名变量 as varchar(10)))
      

  8.   

    declare  cursor1 cursor for select name from select right(name,8) as 表名 from sysobjects where xtype='u' and name like 'kc%'declare @i varchar(1000)open cursor1
    fetch cursor1 into @i
    while @@fetch_status=0
    begin
      exec('insert 你合并后的目标表 (班级号,其他列名) select '''+cast(@i as varchar(10))+''',其他列名 from kc'+cast(@i as varchar(10)))
      fetch cursor1 into @i
    end
    close cursor1
    deallocate cursor1---你的 你合并后的目标表 的表结构要先建好
    ---你要把 其他列名 改为你的列名,顺序要前后一样
    ---但愿你能看懂
      

  9.   

    exec('insert 你合并后的目标表 (班级号,其他列名) select '''+cast(@i as varchar(10))+''',其他列名 from kc'+cast(@i as varchar(10)))
    这一句的意思是从'''+cast(@i as varchar(10))+'''这里取出班级号,然后从这些表里 from kc'+cast(@i as varchar(10)))区其他列名
    ,怎么编译时报错。