当前位置: 代码迷 >> Sql Server >> sql语法求教,该怎么处理
  详细解决方案

sql语法求教,该怎么处理

热度:80   发布时间:2016-04-27 20:46:42.0
sql语法求教
create   table   test   (a   int,数量01月   int,数量02月   int,数量03月   int,数量04月   int,数量05月   int,数量06月   int)
insert   into   test   select   1,100,100,100,100,100,100
            union   select   1,200,200,200,200,200,200
            union   select   1,300,300,300,300,300,300
            union   select   1,400,400,400,400,400,400

Declare   @I   int
select   @I=1
--select   数量+Right([email protected],2)+月 '   from   test       --(语句一)
select   [数量01月]   from   test                                       --(语句二)
drop   table   test

问题:[email protected]
如果:select   @I=5
结果对应为:select   [数量02月]   from   test                                      



------解决方案--------------------
Declare @I int
declare @sql nvarchar(4000)
select @I=1
set @sql= 'select 数量 '+Right([email protected],2)+ '月 from test ' --(语句一)
print @sql
exec(@sql)
  相关解决方案