当前位置:  数据库>sqlserver

T-SQL实例 列别名的用法举例

    来源: 互联网  发布时间:2014-08-29

    本文导语:  T-SQL实例,使用列的别名。 代码: 1> create table employee( --//创建测试用表 2> ID int, 3> name nvarchar (10), 4> salary int, 5> start_date datetime, 6> city nvarchar (10), 7> region char (1)) 8> GO 1> 2> insert...

T-SQL实例,使用列的别名。
代码:

1> create table employee( --//创建测试用表
2>     ID          int,
3>     name        nvarchar (10),
4>     salary      int,
5>     start_date  datetime,
6>     city        nvarchar (10),
7>     region      char (1))
8> GO
1>
2> insert into employee (ID, name,    salary, start_date, city,       region)
3>               values (1,  'Jason', 40420,  '02/01/94', 'New York', 'W')
4> GO

(1 rows affected)
1> insert into employee (ID, name,    salary, start_date, city,       region)
2>               values (2,  'Robert',14420,  '01/02/95', 'Vancouver','N')
3> GO

(1 rows affected)
1> insert into employee (ID, name,    salary, start_date, city,       region)
2>               values (3,  'Celia', 24020,  '12/03/96', 'Toronto',  'W')
3> GO

(1 rows affected)
1> insert into employee (ID, name,    salary, start_date, city,       region)
2>               values (4,  'Linda', 40620,  '11/04/97', 'New York', 'N')
3> GO

(1 rows affected)
1> insert into employee (ID, name,    salary, start_date, city,       region)
2>               values (5,  'David', 80026,  '10/05/98', 'Vancouver','W')
3> GO

(1 rows affected)
1> insert into employee (ID, name,    salary, start_date, city,       region)
2>               values (6,  'James', 70060,  '09/06/99', 'Toronto',  'N')
3> GO

(1 rows affected)
1> insert into employee (ID, name,    salary, start_date, city,       region)
2>               values (7,  'Alison',90620,  '08/07/00', 'New York', 'W')
3> GO

(1 rows affected)
1> insert into employee (ID, name,    salary, start_date, city,       region)
2>               values (8,  'Chris', 26020,  '07/08/01', 'Vancouver','N')
3> GO

(1 rows affected)
1> insert into employee (ID, name,    salary, start_date, city,       region)
2>               values (9,  'Mary',  60020,  '06/09/02', 'Toronto',  'W')
3> GO

(1 rows affected)
1>
2> select * from employee
3> GO
ID          name       salary      start_date              city       region
----------- ---------- ----------- ----------------------- ---------- ------
          1 Jason            40420 1994-02-01 00:00:00.000 New York   W
          2 Robert           14420 1995-01-02 00:00:00.000 Vancouver  N
          3 Celia            24020 1996-12-03 00:00:00.000 Toronto    W
          4 Linda            40620 1997-11-04 00:00:00.000 New York   N
          5 David            80026 1998-10-05 00:00:00.000 Vancouver  W
          6 James            70060 1999-09-06 00:00:00.000 Toronto    N
          7 Alison           90620 2000-08-07 00:00:00.000 New York   W
          8 Chris            26020 2001-07-08 00:00:00.000 Vancouver  N
          9 Mary             60020 2002-06-09 00:00:00.000 Toronto    W

(9 rows affected)
1>
2>
3> --Column AS Alias 列别名的用法
4> SELECT Name + ' ' + City AS CityName FROM Employee
5> GO
CityName
---------------------
Jason New York
Robert Vancouver
Celia Toronto
Linda New York
David Vancouver
James Toronto
Alison New York
Chris Vancouver
Mary Toronto

(9 rows affected)
--删除测试用表employee
1> drop table employee
2> GO

    
 
 
 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • 备份数据库的T-SQL语句
  • T-SQL常用的聚合函数
  • T-SQL常用的数学函数
  • T-SQL 实现一个简单的 Split 函数
  • t-sql/mssql用命令行导入数据脚本的SQL语句示例
  • 使用T-SQL语句创建、修改、删除数据库
  • T-SQL语句创建数据库的例子(图文)
  • t-sql清空表数据的两种方式示例(truncate and delete)
  • 学习T-SQL中default值的使用
  • T-SQL学习之一 T-SQL基础
  • T-SQL常用的元数据函数
  • T-SQL实现的一个Split函数
  • T-SQL常用游标函数实例学习
  • T-SQL判断一个日期是否为今天的函数
  • 用t-sql语句完整备份数据库的例子
  • T-SQL常用的时间和日期函数
  • 使用T-SQL的Split拆分字符串的方法
  • SQLServer用t-sql命令批量删除数据库中指定表(游标循环删除)
  • SQL Server中的T-SQL的基本对象
  • T-SQL常用的系统函数


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3