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
测试结果:
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
测试结果:
相关文章推荐
- 如何获取Oracle share pool中没有使用绑定变量的SQL
- Android 如何定义全局变量 以及 static静态变量使用误区 的问题
- SQL语句如何使用日期作为列
- SQLSERVER 表名数据库名作为变量 必须使用动态SQL(源自网络)
- Oracle中使用PL/SQL如何定义参数、参数赋值、输出参数和 if 判断
- Java 类和对象,如何定义Java中的类,如何使用Java中的对象,变量
- 有如下CAT_s结构体定义,回答: 1) 在一台64位的机器上,使用32位编译,Garfield变量占用多少内存空间?64位编译又是如何?
- 动态sql语句基本语法(字段名,表名,数据库名之类作为变量时,必须用动态SQL如ALTER TABLE中使用程序传递的参数)
- 如何使每条sql语句都变化定义的变量
- 关于怎么在php中定义的sql语句中使用变量
- SQL语句Where中使用别名作为判断条件
- 如何在定义游标的时候使用动态sql语句?
- pl/sql之定义并使用变量,复合类型
- JSP页面如何访问标签中定义的变量-使用实现
- 如何监控并找出系统中存在的大量的未使用绑定变量的SQL
- oracle pl/sql如何定义变量
- 关于Python里MYSQL使用变量作为表名时该如何使用
- C++如何定义多个文件使用全局变量
- 定义和使用SQL变量
- 动态sql语句基本语法(字段名,表名,数据库名之类作为变量时,必须用动态SQL如ALTER TABLE中使用程序传递的参数)