sql-server – 使用RAISERROR在SQL Server 2005中不起作用?

栏目: 数据库 · SQL Server · 发布时间: 5年前

内容简介:翻译自:https://stackoverflow.com/questions/3414825/using-raiserror-isnt-working-in-sql-server-2005

我有以下代码:

BEGIN TRY 

    BEGIN TRANSACTION
       -- DO SOMETHIING

    COMMIT TRAN

END TRY
BEGIN CATCH
   IF(@@TRANCOUNT > 0)
     ROLLBACK TRANSACTION

   RAISERROR(ERROR_MESSAGE(), ERROR_SEVERITY(), ERROR_STATE()) --ERROR: Incorrect syntax near 'ERROR_MESSAGE'.

END CATCH

但是,RAISERROR语句不起作用.提出错误声明有什么问题?

RAISERROR遵循与任何其他存储过程调用相同的规则.传入的参数必须是常量或变量.您不能直接将函数作为参数传递.有关此文档,请参见 Executing Stored Procedures .
/* Demo Code - Functions accept functions as parameters
               while stored procedures do not              */

create function dbo.fnDayOfWeek 
    (@date datetime) 
    returns int
as
begin
    declare @x int
    set @x = DATEPART(day,@date)
    return (@x)
end
go

/* Both statements are successful */
select dbo.fnDayOfWeek('2010-08-06')
go
select dbo.fnDayOfWeek(GETDATE())
go

drop function dbo.fnDayOfWeek
go

create procedure DayOfWeek
    @date datetime
as
begin
    select DATEPART(day,@date)
end
go

/* First call succeeds, second fails */
exec DayOfWeek @date = '2010-08-06'
go
exec DayOfWeek @date = getdate()
go

drop procedure DayOfWeek
go

翻译自:https://stackoverflow.com/questions/3414825/using-raiserror-isnt-working-in-sql-server-2005


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Data Structures and Algorithms in Python

Data Structures and Algorithms in Python

Michael T. Goodrich、Roberto Tamassia、Michael H. Goldwasser / John Wiley & Sons / 2013-7-5 / GBP 121.23

Based on the authors' market leading data structures books in Java and C++, this book offers a comprehensive, definitive introduction to data structures in Python by authoritative authors. Data Struct......一起来看看 《Data Structures and Algorithms in Python》 这本书的介绍吧!

html转js在线工具
html转js在线工具

html转js在线工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具