Alex
Alex

Reputation: 211

How does this statement function?

SQL select Statement

This is a basic select statement, it starts out 'select' then all the rows coming from one table. Why are there '' and what function does that serve? I know about using column and table aliases, or naming a column with a different name 'AS something'. I have seen this several times and never knew what it was trying to perform.

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 

Upvotes: 2

Views: 59

Answers (2)

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171579

The '' is returning an empty string.

The simplest example of this is

select '' as EmptyString

Upvotes: 2

Lukasz Szozda
Lukasz Szozda

Reputation: 176214

This is common pattern when you need some columns from table and the rest is simply placeholder to match desired resultset.

You will get as many rows as in table dbo.LEDGERAP.

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

Upvotes: 6

Related Questions