请教:如何将用变量表示的字段值,赋值给另一个变量?
表a:   年度   1月   2月   3月
       2006   100   500   800
       ....   ...   ...   ...
变量a1等于1月或2月或3月
取年度等于2006的变量a1表示的字段值,赋值给另一个变量a2。
请给出sql范例语句。
谢谢!

解决方案 »

  1.   

    这样吗?create table A(年度 int,[1月] int,[2月] int,[3月] int)
    insert A select 2006,100,500,800declare @para1 int,@para2 int
    select @para1=[1月] from A
    select  @para1
    select @para2=@para1
    select @para2
      

  2.   

    declare @para1 int,@para2 int
    select top 1 @para1=[1月] from A where 年度=2006
    select  @para1
    select @para2=@para1
    select @para2
      

  3.   

    create table tb(年份 int,[1月] int,[2月] int,[3月] int)
    insert into tb select 2006,100,500,800
    godeclare @month nvarchar(20)
    set @month=N'1月'
    declare @year int
    set @year=2006
    declare @t int
    declare @sql nvarchar(4000)
    set @sql=N'select @t=['+cast(@month as nvarchar)+'] from tb where 年份='+cast(@year as nvarchar)
    exec sp_executesql @sql,N'@t int output',@t output
    select @tdrop table tb--这个意思?
      

  4.   

    declare @a1 int,@1a2 int
    select top 1 @a1=[你的月份] from A where 年度=2006
    --select  @a1
    select @a2=@para1
    --select @a2
      

  5.   

    谢谢各位朋友!
    谢谢:xeqtr1982(Visual C# .NET)结果正确。