电脑技术学习

SQL server 2000存储过程

dn001

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