473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

If exist ?

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 32608
chandu031
78 Expert
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 Expert 100+
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
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 Expert 100+
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
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...
12
by: zhisol | last post by:
how can i check if file exist in current directory (in javascript)? -- pozdr;) zhisol
1
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...
2
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...
0
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). ...
4
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...
52
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...
1
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
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.