测试数据:

 

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

 

 

测试结果:

 

 

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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-05
猜你喜欢
  • 2021-10-08
  • 2022-12-23
  • 2021-11-28
  • 2021-07-08
  • 2021-07-30
  • 2021-07-17
  • 2022-12-23
相关资源
相似解决方案