Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does this statement function?

Tags:

sql

sql-server

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 
like image 787
Alex Avatar asked Jan 25 '26 14:01

Alex


2 Answers

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
like image 178
Lukasz Szozda Avatar answered Jan 27 '26 06:01

Lukasz Szozda


The '' is returning an empty string.

The simplest example of this is

select '' as EmptyString

like image 30
D'Arcy Rittich Avatar answered Jan 27 '26 06:01

D'Arcy Rittich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!