473,836 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

If exist ?

26 New Member
Any idea about the DB2 equivalent statement for ‘If Exists’ ??

i'm trying with

[PHP]

IF NOT EXISTS (SELECT * FROM Schema.Table1 WHERE ColumnName = 'I1')
THEN
SELECT * FROM Schema.Table1 WHERE ColumnName = 'I2'
END IF
[/PHP]

i'm gettin error message:-
ERROR [42601] [IBM][DB2/NT] SQL0104N An unexpected token "EXISTS" was found following "IF NOT ". Expected tokens may include: "JOIN". SQLSTATE=42601
please can you help me...

Thanks.
May 30 '07 #1
4 32902
chandu031
78 Recognized Expert New Member
Any idea about the DB2 equivalent statement for ‘If Exists’ ??

i'm trying with

[PHP]

IF NOT EXISTS (SELECT * FROM Schema.Table1 WHERE ColumnName = 'I1')
THEN
SELECT * FROM Schema.Table1 WHERE ColumnName = 'I2'
END IF
[/PHP]

i'm gettin error message:-

please can you help me...

Thanks.
Hi bharadwajrv,

IF NOT exists does EXIST in DB2 and it has the same syntax as what you have mentioned. Your problem might be that of missing semicolons.
Check it out and let me know.

Cheers!
May 31 '07 #2
frozenmist
179 Recognized Expert New Member
Hi,
I believe this is part of a stored procedure.
If so why are you doing a
Select * from table where condition ,
In the if block.
Where are you selecting the values into.
Instead of that give like:
Expand|Select|Wrap|Line Numbers
  1.  
  2.       IF NOT EXISTS (SELECT * FROM Schema.Table1 WHERE ColumnName = 'I1')
  3.       THEN
  4.           SELECT <column> into <variable> FROM Schema.Table1 WHERE ColumnName = 'I2';
  5.       END IF
  6.  
Cheers
May 31 '07 #3
bharadwajrv
26 New Member
Thanks for your reply.

chandu031 - I tried with ";" at end of the statment, but no joy. If you have any example, please can you post them here. Thanks.

frozenmist - Currently this is not a stored procedure... This is a simple inline sql statement in the application...

My requirement is :- need to check if a record exist with value "I1", in that return the record with value 'I1' , if that does not exist, return record with 'i2'..

Any idea on this... Can this be run as a block of SQL statement instead of Stored Proc.

cheers
Venu
May 31 '07 #4
frozenmist
179 Recognized Expert New Member
Hi Venu,
You can run this inside a block

Expand|Select|Wrap|Line Numbers
  1.   BEGIN ATOMIC
  2.       IF NOT EXISTS (SELECT * FROM Schema.Table1 WHERE ColumnName = 'I1')
  3.  
  4.       THEN
  5.             SELECT * FROM Schema.Table1 WHERE ColumnName = 'I2';
  6.  
  7.       END IF;
  8.   END
  9.  
You cant see the result of the select query if you are running it in SQL prompt.
It compiles like a procedure only. You have to get the result set from it then.

Cheers
Jun 1 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
3920
by: jeanfor | last post by:
I get a http 500 error on all asp pages. When turning off the friendly message box, the message is "Class does not exist". What is the fix for that? This affect all asp pages incling the default asp pages in the default directory. Thanks
12
38993
by: zhisol | last post by:
how can i check if file exist in current directory (in javascript)? -- pozdr;) zhisol
1
1770
by: Peter | last post by:
Hi, When my program starts up, it uses MAPILogonEx to connect to the default email profile (set by user). The problem is, if the email profile no longer exist, it would give an error "The profile name is not valid. Enter a valid profile name", after pressing ok, the email profile wizard will come up. We don't want the error message to come up, instead we want to somehow check if the default email profile exist, if it doesn't exist,...
2
17903
by: adam | last post by:
hello What query shoul I send to SQL serwer ( in transact SQL language ) to check does some database exist on serwer ? It similar to problem "does some table exist in database" - resolve to it is query: use db_silnik IF EXISTS (SELECT * FROM prad) PRINT 'table exist'
0
2671
by: Dirk Försterling | last post by:
Hi all, a few days ago, I upgraded from PostgreSQL 7.2.1 to 7.4, following the instructions in the INSTALL file, including dump and restore. All this worked fine without any error (message). Since then, I found lots of the following in the postmaster output: 2003-11-29 15:19:54 ERROR: large object 4838779 does not exist 2003-11-29 15:20:11 ERROR: large object 4838779 does not exist
4
4086
by: Mike | last post by:
Hi, I am looking for function in .Net library that let me know if exist any file if I specified template. Eg: I specify "*.txt" and if any file (1.txt, 2.txt, .. ) exists then I can get True or at least file name . And if does not exist Fasle or empty string. Of course I can use VB6 function Dir, but maybe .Net contains
52
7551
by: paytam | last post by:
Hi all Can anyone tell me how can I check that a file exist or no.I mean when you use this commands FILE *fp; if(!fp) //Could not open the file doen't show why it can not open it,may be the file doesn't exist.Now tell me what should I do! Thanks
1
2674
by: sword | last post by:
This my first starting a new topic in English. I want to ask if I want to judge whether a file exists how I should do. I program with C++. Thank you.
3
21069
by: kang jia | last post by:
hi, currently i am doing booking car online and one of the function is cancel and update booking. if the booking number users entered in is not exist. it will redirect the page stating that the booking number did not exist or you never book with us. however. i would like to express this "if Not exist" concept in my coding. how should i achieve this. the following is my code: def deleteCar(request): if...
3
10389
by: moltendorf | last post by:
I copied the files from my "test" database on my old server (MySQL was not running) to my new server ("./mysql/data/test" folder), and after starting the server, SHOW TABLES; shows all of the tables that are supposed to be there, but running a SELECT * FROM `configuration`; (for example) returns "test.configuration does not exist). I've tried the following repair statement since I'm not too familiar with backing up and restoring data. ...
0
9656
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10821
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10527
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10575
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9358
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6975
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5812
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4001
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3102
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.