I had some SPs that would include a Status column in the output of the table (it always returned a recordset/resultset of some kind). Then I could check the status column:CREATE PROCEDURE getResults @name varchar(30) ASIF EXISTS (SELECT * FROM myTable WHERE name=@name)BEGINSELECT 'Found' AS Status, * FROM myTable WHERE name=@nameRETURNENDELSEBEGINSELECT 'Not Found' AS StatusRETURNEND
I'm not familiar with UDF's yet but you can convert this no problem. It's not a great example but you get the idea. Once it's a UDF you can test it in your calling code like this:DECLARE @search varchar(30)SELECT @search='Smith'IF NOT EXISTS (SELECT * FROM UDFValidate(@search) WHERE Status='Found')BEGINRAISERROR 'Search item "' + @search + '" not found', 16, 1RETURNEND