+ All Categories
Home > Documents > SQL IF EXISTS in RPGIVsqliquery.com/datastore/SQL IF EXISTS in RPGIV.pdf · rpg iv if exists...

SQL IF EXISTS in RPGIVsqliquery.com/datastore/SQL IF EXISTS in RPGIV.pdf · rpg iv if exists...

Date post: 27-Apr-2020
Category:
Upload: others
View: 24 times
Download: 1 times
Share this document with a friend
10
SQL IF EXISTS in RPG IV SQL iQuery Scripting iQ SQLiQuery.com Transforming Db2 into Excel, JSON & more with SQL with Bob Cozzi [email protected] Twitter: @bobcozzi © 2017 Cozzi Productions, Inc.
Transcript

SQLIFEXISTSinRPGIVSQL iQuery Scripting

iQSQLiQuery.comTransforming Db2 into

Excel, JSON & more with SQL

with

[email protected]:@bobcozzi

©2017CozziProductions,Inc.

Programming with SQL iQueryModern SQL Scripting

SQLiQuery.com

iQResultsareblah

TXT

{JSON}CSV

,

Your Data with SQL iQueryYour Data

*WriteoneSQLstatement,outputtoanysupportedformat.©2016CozziProductions,Inc.

*WriteOneandDone!

DownloadthisPresentation

WhatisSQL"IFEXISTS"

• Testsifthesubselect producesanyrows• Ifrowsarereturned,theIFtestistrue• Ifnorowsarereturned,theIFtestisfalse• SQLUDFsand"stored"ProceduressupportIFExiststests• SQLiQuerySupportsIFExiststests• WhataboutRPG?

SQLiQueryScript

IfarecordexiststhatmatchestheWHEREclause,thenDO.

RPGIVIFExists

5770ST1 V7R3M0 160422 Create SQL ILE RPG Object IFEXISTSDIAGNOSTIC MESSAGES

4 EXEC SQL IF EXISTS (SELECT * FROM DATALIB.ORDHIST 5770ST1 V7R3M0 160422 Create SQL ILE RPG Object IFEXISTS

DIAGNOSTIC MESSAGESMSG ID SEV RECORD TEXT SQL0199 30 4 Position 22 Keyword IF not expected. Valid tokens: ( CL

END GET SET CALL DROP FREE HOLD LOCK OPEN WITH ALTER BEGIN.

WhatCanWeDoinRPG?

• RPGIVdoesnotsupportIFEXISTS• UsingRPGandSQLwecanworkaroundthislimitation

HowtoCode"IFEXISTS"inRPGIVwithSQL

• IFEXISTSdoesnotexistinRPG• HoweverRPGdoeshaveIFstatementitself

• RPGsupportstheSQLWHEREEXISTSclause• WecancombinedRPGwithSQLtosimulatethe"IFEXISTS"condition

IFEXISTSinRPG

1.Addan"IfExists"flag(indicatorvariable)

2.SELECT'1'INTOthatvariablefromSYSDUMMY1

3.NesttheEXISTSclausewithintheWHEREclause

4.TesttheExistsvariablefortrue(*ON)condition

/free

/end-free

DownloadthisPresentationandAFreeTrialofSQLiQueryToday


Recommended