2007-02-03

SQL server 2000存储过程

来源: CSDN 作者:佚名 评论 0 条
  if exists(select name from sysobjects where name='GetRecord' and type = 'p')
drop procedure GetRecord
GO

create procedure GetRecord
@id int output, --输出p_id和p_path
@path nvarchar(255) output
as

select top 1 @id = p_id, @path = p_path from n_project where p_flag = '0';
if(@id > 0)
Update n_project set p_flag = '1' where p_id = @id
else
begin
set @id = 0; --若没有结果则给个默认值,否则直接返回NULL会使程序错误
set @path = ' '; --若p_path为NULL,则它也会返回NULL,从而造成程序错误
end
if(@path is NULL)
begin
set @path = ' ';
end

if @@error=0
print 'Good'
else
print 'Fail'
go

--测试程序
declare @idd int
declare @ppath nvarchar(255)
EXEC dbo.GetRecord @idd output,@ppath output
select '1'=@idd, '2'=@ppath
go

SQL SERVER中,按CTR 0,即可输入空值NULL


http://blog.csdn.net/gzq400/archive/2007/02/02/1501235.aspx


(本文仅表明作者个人观点,不代表本站及其管理员立场.) 推荐 收藏 投稿 打印 返回 关闭
上一篇:sql server行转列问题终极解决  
下一篇:SQL Server常用到的几个设置选项
    评论加载中…
 推荐文章
     

网站首页  -  网站地图 -   站长论坛  -  网站投稿  -    -  网站管理
Copyright © 2008 芜湖站长站 All Rights Reserved 皖ICP备07500611号