Hi Tonkuma...
Thanks for the statements ..
it worked fine...
I have one more twist to the problem...
The query is a part of a web application...
It checks whether the emp number is already present...other wise it
inserts...
**Now, if it is already present, it shows a warning
SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result
of a
query is an empty table. SQLSTATE=02000
** Can i have this as a part of a case statement....That is why i am
purticular on Case..
Would be of great help if some one can make the first select case
work....
Some thing like,
Select
case
# do this
MERGE INTO tariq.test A
USING (VALUES (3257,'Merge') ) B(emp_num, emp_name)
ON A.emp_num =B.emp_num
WHEN NOT MATCHED THEN
INSERT
VALUES (B.emp_num, B.emp_name)
ELSE IGNORE;
Else
# do nothing
** I am a newbie in Db2, trying to get the basics right and thanks for
your help once again Liu Liu, Tonkuma,Celko
Serge Rielau - 16 Feb 2006 13:09 GMT
> Hi Tonkuma...
>
[quoted text clipped - 11 lines]
> of a
> query is an empty table. SQLSTATE=02000
That's OK. Warnings are nothing evil. Simply ignore it if you don't care.
> ** Can i have this as a part of a case statement....That is why i am
> purticular on Case..
> Would be of great help if some one can make the first select case
> work....
The MERGE statement is the Right(tm) answer. That's why we are
particular about not using a "case".
What you have poste btw is a CASE-_expression_ which does not support
embedded statement.
If you wanted to write a CASE _statement_ you so so in your preferred
language.
In an SQL Procedure (!) it looks something like this:
CREATE PROCEDURE ...
BEGIN ....
CASE WHEN NOT EXISTS(......)
THEN INSERT ....;
END CASE;
...
END
The difference between a CASE expression and CASE statement is that the
first operates on "mathematical: expressions. That is "values" are the
arguments and it returns one of the arguments.
A case statement has statements as arguments and returns nothing because
it's purely procedural control flow.
Cheers
Serge

Signature
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Eugene F - 16 Feb 2006 16:07 GMT
You can check to see if the DB2 driver that your application is using
to communicate with DB2 database can be set to suppress warnings from
DBMS. Also, if the driver supports that, instead of embedding SQL in
your application, consider calling a stored procedure where you have
much more flexibility to handle your logic and exceptions/warnings as
well.
-Eugene
Tonkuma - 17 Feb 2006 03:02 GMT
If you are using these statements in Stored Procedure, I think that you
can use GET DIAGNOSTICS statement to get returned message text of a
statement executed just before.
rAinDeEr - 17 Feb 2006 05:01 GMT
Hi all,
Thanks for the output...
I had a great learning and new options to use :-)
~ ME