当前位置: 首页 > 图文教程 > 数据库 > MSSQL > SQL server 2000存储过程

MSSQL
SQL 实用语句
SQL Server 版本变更检查 警告
创建动态MSSQL数据库表
常用SQL功能语句
table 行转列的sql详解
三步堵死 SQL Server注入漏洞
sql 去零函数 datagridview中数字类型常出现后面的零不能去掉
insert into tbl() select * from tb2中加入多个条件
Sql Server 字符串聚合函数
通过备份记录获取数据库的增长情况
sqlserver 2000 远程连接 服务器的解决方案
SQL 合并多行记录的方法总汇
批处理 动态sql
在sp_executesql中使用like字句的方法
SQL中的left join right join
Sql Server 数据库索引整理语句,自动整理数据库索引
查询数据排名情况SQL
sqlserver 比较两个表的列
mssql 两表合并sql语句
SQL SERVER 文件和文件组

MSSQL 中的 SQL server 2000存储过程


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-30   浏览: 78 ::
收藏到网摘: n/a

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