Grayson Hampton
asked on
SQL Case Statement used with an Alias
Is there a way to use a Case Statement with an alias.
I would like Case statement to return a 0 or 1 based on preContPaid
SELECT Name
RTRIM([CompanyID) + ' ' + RTRIM([CustomerNumber) + ' ' + RTRIM([JobNumber) as [preContPaid],
CASE
WHEN [preContPaid] = NULL
THEN NULL
ELSE [preContPaid]
FROM Jobs_Rept
I would like Case statement to return a 0 or 1 based on preContPaid
SELECT Name
RTRIM([CompanyID) + ' ' + RTRIM([CustomerNumber) + ' ' + RTRIM([JobNumber) as [preContPaid],
CASE
WHEN [preContPaid] = NULL
THEN NULL
ELSE [preContPaid]
FROM Jobs_Rept
ASKER
@slightwv...
I am receiving an "incorrect syntax" error on "from CTE"
I am receiving an "incorrect syntax" error on "from CTE"
ASKER
Nevermind...I forgot the "End"
ASKER
@slightwv...
The query is not returning "SELECT Name,"
I want it to also show other fields that are not part of the alias
The query is not returning "SELECT Name,"
I want it to also show other fields that are not part of the alias
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for your help.
Nothign can '=' null so you need to use "is null".
Not sure how your will get a null concatenating a ' ' in the string.
Anyway, either a CTE or sub select.
Open in new window