Want to use if then instead of Case end in Transact SQL

Using Transact SQL in SQL SERVER Management studio.  I have always used a Case statement when choosing. Can I use an If then

Example:
SELECT [Order ID],
[Order Amount],
[Order date],
if shipped = 1 then
    'yes'
else
   'no'
End  as shipStatus
FROM Orders
WHERE [Order ID] between 2934 and 2944
chaverlyAsked:
Who is Participating?
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.

slightwv (䄆 Netminder) Commented:
CASE is the same thing as IF-THEN-ELSE.  Why would you want to use a different syntax?
0
Éric MoreauSenior .Net ConsultantCommented:
You just cannot embed a IF into a SQL statement. IF can only be used for control-flow. https://docs.microsoft.com/en-us/sql/t-sql/language-elements/if-else-transact-sql?view=sql-server-2017
0
Dale FyeCommented:
Not sure why you would want to do so, when CASE is so easy to use.
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

chaverlyAuthor Commented:
Am teaching a class and student remarked that they had seen an if then statement in a report they inherited.
0
Éric MoreauSenior .Net ConsultantCommented:
maybe in a SP or a function but in a SQL Query per say
0
slightwv (䄆 Netminder) Commented:
0
Scott PletcherSenior DBACommented:
Explain to your student that the ANSI-standard, i.e. "best practice", way of testing within SQL is to use a CASE statement.

MS stupidly decided to allow IIF structure, going down the road of [Oracle's] PL/SQL, which has become an incongruous mish-mash of half a dozen language syntaxes rolled into "one language".  

If you look at the query plan, you'll see that the IIF gets converted into a CASE, because that is the way SQL does such condition checking.

Thus, don't teach your students to write poor code just because they can.  You can still write joins like this:

SELECT ... FROM t1, t2 WHERE t1.id = t2.id

rather than using a JOIN clause, but that doesn't mean you should, because you shouldn't.
0

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
Dale FyeCommented:
You can use many functions that are more aligned with VB or VBA than with SQL Server within expressions in SSRS.

I found it very confusing when I started working with SSRS.
0
chaverlyAuthor Commented:
Thank you for getting back to me.  I really appreciate your help.
0
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
SQL

From novice to tech pro — start learning today.