存储过程 执行某条语句成功如何表示成功执行

lilinew 2006-11-27 11:55:10
存储过程 执行某条语句成功如何表示成功执行
需要表示成功执行某条语句
象vb的debug print语句打印 该语句的成功与否执行

如insert into .....1
如何表示print语句打印 "ok"

insert into .....2
如何表示print语句打印 "ok"

insert into .....3
如何表示print语句打印 "ok"


如何表示print语句打印 "ok"

具体需求(判断是否当前天为星期一):
declare @xinqi varchar(10);
--xinqi="星期一";
select @xinqi=DATENAME(dw,getdate());
接下来不知道如何写判断是否为星期一
--if xinqi=="星期一"
--print "dfdf"

...全文
169 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
mpss 2006-11-27
  • 打赏
  • 举报
回复
下面的示例取决于 INSERT 和 DELETE 语句的成功操作。局部变量在两条语句后均被设置为 @@ERROR 的值,并且用于此操作的共享错误处理例程中。

USE pubs
GO
DECLARE @del_error int, @ins_error int
-- Start a transaction.
BEGIN TRAN

-- Execute the DELETE statement.
DELETE authors
WHERE au_id = '409-56-7088'

-- Set a variable to the error value for
-- the DELETE statement.
SELECT @del_error = @@ERROR

-- Execute the INSERT statement.
INSERT authors
VALUES('409-56-7008', 'Bennet', 'Abraham', '415 658-9932',
'6223 Bateman St.', 'Berkeley', 'CA', '94705', 1)
-- Set a variable to the error value for
-- the INSERT statement.
SELECT @ins_error = @@ERROR

-- Test the error values.
IF @del_error = 0 AND @ins_error = 0
BEGIN
-- Success. Commit the transaction.
PRINT "The author information has been replaced"
COMMIT TRAN
END
ELSE
BEGIN
-- An error occurred. Indicate which operation(s) failed
-- and roll back the transaction.
IF @del_error <> 0
PRINT "An error occurred during execution of the DELETE
statement."

IF @ins_error <> 0
PRINT "An error occurred during execution of the INSERT
statement."

ROLLBACK TRAN
END
GO

22,301

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧