SQL CASE Statement - The IIF Alternative for SAP Business One/HANA Databases (2024)

Table of Contents
Contents: The Problem The Solution

If you're working on an older or alternate SQL server, the IIF function may not be supported, instead you'll want to use a CASE statement.

Contents:

The Problem

The Solution

The Problem

When writing queries in SAP Business One or alternative SQL servers, you may get a syntax error when trying to use the IIF function to add in some logic to your queries.

For instance, let's say that you are trying to use IIF to specify that if the ItemCode from table alias T0, was 'Shipping Charges', then return price before distribution, otherwise, multiple the quantity by average price, and call it TotalLineCost:

IIF(T0."ItemCode" = 'Shipping Charges', T0."PriceBefDi", T0."Quantity" * T4."AvgPrice") As "TotalLineCost"

If you tried to run this in SAP Business One or in an older SQL server, a syntax error that states: "SQL Syntax error: incorrect syntax near "=" ... 'User-Defined Values'" would be thrown.

It may be a little bit hard to diagnose what is going on here, as you may assume that IIF would work here just as with other SQL servers.

The Solution

Because the IFF Function is not available on all SQL servers (SAP Business One being one of them), we need a work around solution.

In this scenario, we should look to use a CASE statement, as CASE is portable across all SQL platforms whereas IIF is SQL SERVER 2012+ specific. You can replace the IIF function with a CASE statement, and this solution will function mostly the same.

The IIF statement above can be re-written using a CASE statement as show below:

CASE WHEN T0."ItemCode" = 'Shipping Charges' THEN T0."PriceBefDi" ELSE T0."Quantity" * T4."AvgPrice"END AS "TotalLineCost"

The CASE statement operates just like the IF function in Excel, or the IIF function, but is structured a bit differently.

The CASE statement will go through specified conditions for each WHEN, and when the condition is met, return the value or result held in the THEN line. If no conditions are met, then the value in the ELSE line will be returned.

So, the code above is states that whenever the 'ItemCode' is equal to 'Shipping Charges', then return the price before distribution, otherwise multiply quantity by average price.

SQL CASE Statement - The IIF Alternative for SAP Business One/HANA Databases (2024)
Top Articles
Overwintering Honeybees In A Single Deep Super - Wildflower Meadows
Five Techniques and Tools to Boost Your Productivity
Evil Dead Movies In Order & Timeline
Places 5 Hours Away From Me
Moon Stone Pokemon Heart Gold
Cad Calls Meriden Ct
Beacon Schnider
CKS is only available in the UK | NICE
Dr Lisa Jones Dvm Married
Red Wing Care Guide | Fat Buddha Store
Irving Hac
Lesson 1 Homework 5.5 Answer Key
South Ms Farm Trader
Charmeck Arrest Inquiry
Zürich Stadion Letzigrund detailed interactive seating plan with seat & row numbers | Sitzplan Saalplan with Sitzplatz & Reihen Nummerierung
Funny Marco Birth Chart
Maplestar Kemono
Bcbs Prefix List Phone Numbers
SXSW Film & TV Alumni Releases – July & August 2024
Amc Flight Schedule
Spectrum Field Tech Salary
The best TV and film to watch this week - A Very Royal Scandal to Tulsa King
Bernie Platt, former Cherry Hill mayor and funeral home magnate, has died at 90
Veracross Login Bishop Lynch
Morristown Daily Record Obituary
Apartments / Housing For Rent near Lake Placid, FL - craigslist
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Albert Einstein Sdn 2023
Hefkervelt Blog
Walgreens On Bingle And Long Point
Weathervane Broken Monorail
Wrights Camper & Auto Sales Llc
Safeway Aciu
Www.craigslist.com Syracuse Ny
Song That Goes Yeah Yeah Yeah Yeah Sounds Like Mgmt
Smartfind Express Henrico
Tgh Imaging Powered By Tower Wesley Chapel Photos
Space Marine 2 Error Code 4: Connection Lost [Solved]
Review: T-Mobile's Unlimited 4G voor Thuis | Consumentenbond
Mytime Maple Grove Hospital
Energy Management and Control System Expert (f/m/d) for Battery Storage Systems | StudySmarter - Talents
فیلم گارد ساحلی زیرنویس فارسی بدون سانسور تاینی موویز
Pgecom
Holzer Athena Portal
The Jazz Scene: Queen Clarinet: Interview with Doreen Ketchens – International Clarinet Association
Fresno Craglist
Helpers Needed At Once Bug Fables
Edt National Board
King Fields Mortuary
Syrie Funeral Home Obituary
Heisenberg Breaking Bad Wiki
Varsity Competition Results 2022
Latest Posts
Article information

Author: Terrell Hackett

Last Updated:

Views: 6038

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Terrell Hackett

Birthday: 1992-03-17

Address: Suite 453 459 Gibson Squares, East Adriane, AK 71925-5692

Phone: +21811810803470

Job: Chief Representative

Hobby: Board games, Rock climbing, Ghost hunting, Origami, Kabaddi, Mushroom hunting, Gaming

Introduction: My name is Terrell Hackett, I am a gleaming, brainy, courageous, helpful, healthy, cooperative, graceful person who loves writing and wants to share my knowledge and understanding with you.