1 概述學習
本篇文章簡要分析,在SQL SERVER中,AS的基本用法。spa
2 具體分析3d
2.1 定義變量類型code
1 DECLARE @UserName AS VARCHAR(50)='Alan_beijing'
2.2 取別名blog
2.2.1 爲結果集列取別名ci
code:博客
1 SELECT OrderID,CustID,OrderDate 2 FROM Orders
result:it
code:class
1 SELECT OrderID AS '訂單ID',CustID AS '顧客ID',OrderDate AS '訂單日期' 2 FROM Orders
result:基礎
2.2.2 爲表取別名
1 SELECT O.OrderID,O.CustID,O.OrderDate 2 FROM Orders AS O
2.2.3 爲子查詢取別名
1 SELECT ChildQuery_Orders.OrderDate 2 FROM 3 (SELECT * 4 FROM Orders 5 WHERE CustID>=5) AS ChildQuery_Orders
2.3 轉換類型
2.3.1 CAST類型轉換
1 SELECT CAST('110' AS INT) --110
2.3.2 CONVERT類型轉換
1 SELECT CONVERT(decimal, '123.6') -- 123
2.4 建立視圖,表示基表來源
1 CREATE VIEW ViewDemo 2 AS 3 SELECT * FROM Orders
2.5 其餘(後續補充)
3 參考文獻
【01】Microsoft SqlServer 2008技術內幕:T-SQL 語言基礎
【02】Microsoft SqlServer 2008技術內幕:T-SQL 查詢
4 版權