---
title: "How to Write IF Condition in SQL Stored Procedure Correctly"
description: "The best way to understand IF coding in SQL stored procedure and in COBOL with simplified examples really good for quick refresh."
url: https://srinimf.com/2017/02/01/the-best-tricky-tip-stored-procedure-if-and-cobol-if/
date: 2017-02-01
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2017/02/pexels-photo-289586.jpeg?fit=1880%2C1144&ssl=1
categories: ["COBOL", "SQL"]
tags: ["How to code if in stored procedure excellent way"]
type: post
lang: en
---

# How to Write IF Condition in SQL Stored Procedure Correctly

I am just in very good mood in the morning having strong ginger tea. Just I got an excellent idea on [Stored procedure](https://srinimf.com/2021/11/27/how-to-run-stored-procedure-in-sql-developer/) with SQL.

The exact point that I need to say i[s difference](https://srinimf.com/2015/12/25/2-best-differences-of-db2-declare-cursor-and-describe-cursor/) in coding of if condition for both COBOL and SQL procedure.

Related[How to Begin Coding in Python: A Simple Action Plan](https://srinimf.com/2025/06/28/how-to-begin-coding-in-python-a-simple-action-plan/)

In **COBOL**, you **write** IF **condition** like below.

Related[How to Say Correctly – If DB2 down will Pre-compilation successful](https://srinimf.com/2016/03/23/db2-pre-compilation-during-db2-is-down-interview-question/)

```
IF EXPRESSION 
  DO THIS
ELSE
   DO THIS
END-IF
```

**In** **SQL** **procedure**

```
Connect ap/ap;
Set serveroutput on;
Declare
   Variable declaration...
BEGIN
   IF EXPRESSION  THEN
          DO THIS
   ELSEIF  Expression THEN
        DO THIS
   ELSE
       DO THIS
   END IF;
END;
/
```

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2017%2F02%2F01%2Fthe-best-tricky-tip-stored-procedure-if-and-cobol-if%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2017%2F02%2Fpexels-photo-289586.jpeg%3Ffit%3D1200%252C730%26ssl%3D1&description=How%20to%20Write%20IF%20Condition%20in%20SQL%20Stored%20Procedure%20Correctly)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2017/02/01/the-best-tricky-tip-stored-procedure-if-and-cobol-if/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2017/02/01/the-best-tricky-tip-stored-procedure-if-and-cobol-if/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2017/02/01/the-best-tricky-tip-stored-procedure-if-and-cobol-if/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2017/02/01/the-best-tricky-tip-stored-procedure-if-and-cobol-if/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20How%20to%20Write%20IF%20Condition%20in%20SQL%20Stored%20Procedure%20Correctly&body=https%3A%2F%2Fsrinimf.com%2F2017%2F02%2F01%2Fthe-best-tricky-tip-stored-procedure-if-and-cobol-if%2F&share=email)
-

### Like this:

Like Loading…
