1: declare @Name char(10)
   set @name='01200308'
   exec('select * from'+ @Name)
2:left(yourDataField,4)   

解决方案 »

  1.   

    exec('select * from '+@Name)substring('200301',1,4)
      

  2.   

    1 exec('select * from '+@name)
    2 exec('select * from '+@name+'where substring('200301',1,4)='2003'')
      

  3.   

    我不想用exec
    怎么办?我一年12各表呀
      

  4.   

    declare @Name char(10)
       declare @s char(10)   set @name='01200308'
       exec('select @s=Field1 from ' + @Name)如何返回@s 呀!不行把
      

  5.   

    select @Namesubstring('200301',1,4)
      

  6.   

    declare @Name char(10)
       declare @@s char(10)   set @name='01200308'
       exec('select @@s=Field1 from ' + @Name)select @@s
      

  7.   

    我不想用exec
    怎么办?我一年12各表呀
    declare @Name char(10)
       declare @s char(10)   set @name='01200308'
       exec('select @s=Field1 from ' + @Name)如何返回@s 呀!
      

  8.   

    exec('select Field1 into @@s from ' + @Name)select * from @@sdrop table @@s
      

  9.   

    1、declare @Name char(10)
       set @name='01200308'
       exec('select * from ['+@Name+']') 
       
        
    2、我的数据按月存储如:表‘200301’,‘200302’ 如何查询一年的数据??
    建立视图:create view [2003]
    as
    select * from [200301]
    union all
    select * from [200302]
    union all
    select * from [200303]
    union all
    select * from [200304]
    union all
    select * from [200305]
    union all
    select * from [200306]
    union all
    select * from [200307]
    union all
    select * from [200308]
    union all
    select * from [200309]
    union all
    select * from [200310]
    union all
    select * from [200311]