4

我想在我的查询中打印一条消息(“数据库中不存在该表雇员”)。

我的查询是:

create proc sp_emprecord
as 
begin
    select * from employe
end

begin try
    execute sp_emprecord
end try

begin catch
    select
    error_message() as errormessage,
    error_number() as erronumber,
    error_state() as errorstate,
    error_procedure() as errorprocedure,
    error_line() as errorline;
 end catch
4

1 回答 1

9

尝试这个:

create proc sp_emprecord
as 
begin
    select * from employe
end
go
begin try
    execute sp_emprecord
end try

begin catch
    if(ERROR_NUMBER() = 208)
        RAISERROR ('The table employe is not exist in database', 0, 1) WITH NOWAIT;
    else
        select
        error_message() as errormessage,
        error_number() as erronumber,
        error_state() as errorstate,
        error_procedure() as errorprocedure,
        error_line() as errorline;
 end catch
于 2012-09-07T14:03:15.627 回答