这个陈述如何发挥作用?

时间:2018-05-08 14:41:03

标签: sql sql-server

SQL select Statement

这是一个基本的select语句,它从'select'开始,然后是来自一个表的所有行。为什么会有这样的功能? 我知道使用列和表别名,或命名一个名称为“AS something”的列。我已经多次看过这个,但从来不知道它想要表演的是什么。

SELECT '' AS prSkipCustomInfo
       , '' AS WBS1
       , '' AS WBS2
       , '' AS WBS3
       , '' AS SubLevel1
       , '' AS SubLevel2
       , '' AS SubLevel3
       , '' AS WBS1Name
       , '' AS ProjectManager
       , '' AS Principal
       , '' AS Supervisor
       , '' AS ClientID
       , '' AS ContactID
       , '' AS ChargeType
       , '' AS revType
       , '' AS currencyCodeProj
       , '' AS currencyCodeBill
       , '' AS currencyCodeFunct
       , '' AS currencyCodePres
       , 0 AS currencyCodeProjCount
       , 0 AS currencyCodeBillCount
       , 0 AS currencyCodeFunctCount
       , 0 AS currencyCodePresCount
       , '' AS Account
       , '' AS TransType
       , '' AS SubType
       , '' AS Transfer
       , '' AS rectype
       , '' AS rectypelabel
       , '' AS rectypesub
       , '' AS rectypesublabel
       , 0 AS Period
       , 0 AS PostSeq
       , TransDate
       , '' AS RefNo
       , '' AS Desc1
       , '' AS Desc2
       , 0.00 AS Amount
       , '' AS Invoice
       , 0 AS Line
       , '' AS VendOrg
       , '' AS XferWBS1
       , '' AS XferWBS2
       , '' AS XferWBS3
       , '' AS BillStatus
       , '' AS AcctName
       , '' AS AcctClass
       , '' AS AcctSubClass
       , '' AS Org
       , '' AS Vendor
       , '' AS VendName
       , '' AS VendUnit
       , '' AS Voucher
       , '' AS Documents
       , '' AS PKey
       , 0 AS UnitQuantity
       , 0.00 AS UnitBillRate
       , 0.00 AS UnitCostRate
FROM   dbo.LedgerAP 

2 个答案:

答案 0 :(得分:6)

当您需要表中的某些列时,这是常见的模式,其余的只是占位符以匹配所需的结果集。

您将获得与表dbo.LEDGERAP中一样多的行。

SELECT
  '' AS prSkipCustomInfo,
  -- ...
   TransDate,                   --here goes actual value from source table
  --...
FROM dbo.LedgerAP

答案 1 :(得分:2)

''返回一个空字符串。

最简单的例子是

select '' as EmptyString