IF EXISTS for SELECT statements
Posted by:
Tom Dean
Date: July 07, 2005 01:37PM
I've searched around but can't find an answer for this one. I'm trying to duplicate this T-SQL code from MSSQL:
if exists(SELECT 1 FROM table WHERE id=@id)
begin
// do something here....
end
Any help would be greatly appreciated!
On another note, I read that there are plans, or at least a feature request, to support something along the lines of T-SQL's @@ERROR, where in you can check if an error occurred exactly after a statement. Example:
INSERT INTO table (col1, col2, col3) VALUES (val1, val2, val3)
if (@@ERROR <> 0)
begin
// An error occurred and we'll handle it here
end
Basically I need the means to respond to a an error for a specific query, and not just an error code.
Additionally, is it possible to setup a general catch-all error block? Will the SQLEXCEPTION catch all errors?
Thanks in advance!