您的位置:首页 > 数据库

SQL中如何将定义的变量作为列 别名 使用

2013-04-02 11:37 134 查看
测试数据:

create table test
(
value int not null
) -----drop table test

insert into test (value)
select 2
union all
select 3
union all
select 2
union all
select 7
union all
select 6
union all
select 3
union all
select 5
union all
select 6
union all
select 8
union all
select 4
union all
select 9
union all
select 4
union all
select 1
union all
select 2

select * from test declare @cc int
declare @str varchar(8000)
set @cc=9999

print @cc
set @str='select value as '+'['+cast(@cc as varchar(10))+']'+'from test'
print @str

测试结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: