TSQL syntax help – how to return a null value

Hi All,

I have the following line in a sproc:
--------------------------
MX_Reg_Is_MatureStudent

--------------------------
It returns a true or false value as it is a Boolean field. There is always a value.
However, I only want it to return the word ‘XXXX’ if True else it should return a Null value.

Many thanks
LVL 5
Abiel de GrootDeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulEE Topic AdvisorCommented:
CASE WHEN MX_Reg_Is_MatureStudent=1 THEN  ‘XXXX’ ELSE NULL END

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Abiel de GrootDeveloperAuthor Commented:
Many thanks Paul ;-)

A
Vitor MontalvãoMSSQL Senior EngineerCommented:
It's a function, right?
So:
CASE MX_Reg_Is_MatureStudent()
    WHEN 1 THEN  ‘XXXX’ 
    ELSE NULL 
END 

Open in new window

The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Abiel de GrootDeveloperAuthor Commented:
Hi Victor,

Sorry, just closed it as you arrived ;-)

Thanks anyway
Vitor MontalvãoMSSQL Senior EngineerCommented:
No worries.
I just thought that Paul's solution didn't work because he didn't add the parenthesis. But seems that it worked after all :)
Cheers
PortletPaulEE Topic AdvisorCommented:
Many thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.