首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql语法求教,该怎么处理

2012-03-02 
sql语法求教createtabletest(aint,数量01月int,数量02月int,数量03月int,数量04月int,数量05月int,数量06

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(100+@I,2)+月 '   from   test       --(语句一)
select   [数量01月]   from   test                                       --(语句二)
drop   table   test

问题:要求语句二对应@I
如果:select   @I=5
结果对应为:select   [数量02月]   from   test                                      



[解决办法]
Declare @I int
declare @sql nvarchar(4000)
select @I=1
set @sql= 'select 数量 '+Right(100+@I,2)+ '月 from test ' --(语句一)
print @sql
exec(@sql)

热点排行