Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to print friendly error messages

Author  Topic 

tomex1
Starting Member

47 Posts

Posted - 2008-08-07 : 11:27:50
Hi all,
I am trying to print a friendly error message in my procedure. My procedure contains a select statement and want to be able to print my custom message whenever the select statement returns more than on row. Please, how do I do this?

Kind regards,
Segun

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-07 : 11:30:08
use RAISEERROR

http://blogs.techrepublic.com.com/datacenter/?p=390
Go to Top of Page

tomex1
Starting Member

47 Posts

Posted - 2008-08-07 : 11:42:43
quote:
Originally posted by visakh16

use RAISEERROR

http://blogs.techrepublic.com.com/datacenter/?p=390



Hi,
many thanks for this but I am not sure if this is what I need. I would have thought I could use an 'IF' statement or something along that line.

Kind regards,
Segun
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-08-07 : 14:54:52
yes you can. visakh16 was merely saying that you could use RAISERROR to actually print the message.

You would do an IF condition I guess like this..

<your query>

IF @@ROWCOUNT > 1 BEGIN
RAISERROR('yourMessage', severity (number from 1 to 20 I think), level (an INT)
END

Check out books on line for more info.

RAISERROR also accepts a WITH (NOWAIT) command which means that the string is returned to your application / the screen immediately rather than waiting for caching.

EXAMPLE

RAISERROR('Hello World', 0, 1) WITH NOWAIT

-------------
Charlie
Go to Top of Page
   

- Advertisement -