Anyone know of a try/catch equivalent on db2?
I googled sql try catch, but the result is for mssql. Pretty cool actually. I tried it on our mssql box, but the db2 box didn't like it.
mssql:
Code:
BEGIN TRY
CREATE TABLE myschema.DBO.TRYTHIS
(
ID VARCHAR(8)
)
END TRY
BEGIN CATCH
DROP TABLE myschema.DBO.TRYTHIS
END CATCH
A solution like this would speed many of our queries because sometimes subqueries need to be run twice such as
Code:
with sq as
(select value from sourcetable where cond)
select case when sq is null then 0 else sq from sourcetable2
if the query could be rewritten as
Code:
with sq as
(select value from sourcetable where cond)
select begin try sq end try begin catch 0 end catch from sourcetable2
The query would execute once instead of twice for every row.