首 页 | 精品电影 | 音乐天堂 | 在线游戏 | Flash MTV | 三湘书屋 | 幽默笑话 | 三湘图库 | 美女写真 | IT知识库 | QQ贴图 | 加入书签

网页制作网络编程图形图象操作系统冲浪宝典软件教学网络安全认证考试通信技术电子商务业内动态书籍教程原码

最近更新 文章分类 多媒体类 精品软件

本站搜索:
您的位置:三湘时空 -> IT知识库 -> 文章分类 -> 数据库技巧 -> 存储过程使用技巧
存储过程使用技巧


文章类别:数据库技巧 来源: 作者: 发表日期:2006-11-16 字体:[ ]

小游戏 | 在线影院 | 幽默笑话 | 源码下载 | Flash MTV | 音乐试听 | 书屋 | 美女写真

================以下是存储过程================
/*
加入一条基本信息
库存商品

-1 inttostr 失败
-2 有相关数据存在
-3 parid 不存在
-4 记录已存在
*/

CREATE PROCEDURE F_B_InsertP
(@Parid varchar(25),
@dbname varchar(30),
@FullName varchar(66),
@Namevarchar(30),
@UserCode varchar(26),
@Standard varchar(120),
@Type varchar(40),
@Area varchar(30),
@Unit1 varchar(8),
@Unit2 varchar(8),
@UnitRate1 numeric(18,4),
@UnitRate2 numeric(18,4),
@preprice1 numeric(18,4),
@preprice2 numeric(18,4),
@LifeMonth int,
@LifeDay int,
@Comment varchar(256),
@namepyvarchar(60),
@Barcodevarchar(30)
)
AS
Declare @nReturntype int
Declare @EtypeId_1 varchar(25)
Declare @nSoncount int
Declare @nSonnum int
Declare @leveal smallint
Declare @ParRec int
Declare @checkValue int

-- 取得ID号

exec @nReturntype=F_B_createId @ParId,@dbname,@EtypeId_1 out,@nSonnum out,@nSoncount out,

@ParRec out

if @nReturntype=-101 goto error111
if @nReturntype=-102 goto error112
if @nReturntype=-103 goto error113


Exec @checkValue=mzw_CheckBasicSet
if @checkValue=1 -- 查找编号和全名不能完全相同
begin
if exists(Select [typeid] From ptype Where [typeId]=@EtypeId_1 or ([fullname]=@fullname
and [usercode]=@usercode) and [deleted]<>1) goto error114
end
if @checkValue=2--全名不能完全相同
begin
if exists(Select [typeid] From ptype Where [typeId]=@EtypeId_1 or ([fullname]=@fullname
) and [deleted]<>1) goto error114
end
if @checkValue=3--编号不能完全相同
begin
if exists(Select [typeid] From ptype Where [typeId]=@EtypeId_1 or (
[usercode]=@usercode) and [deleted]<>1) goto error114
end
if @checkValue=4 -- 查找编号和全名不能完全相同
begin
if exists(Select [typeid] From ptype Where [typeId]=@EtypeId_1 or ([fullname]=@fullname
or [usercode]=@usercode) and [deleted]<>1) goto error114
end
if (len(@Barcode)>0)
begin
if exists(Select * From ptype
Where ([Barcode]=@Barcode) and [deleted]<>1) return -5
end

BEGIN TRAN InsertP

Select @leveal=[leveal] From ptype Where [typeid]=@Parid
Select @leveal=@leveal+1

Insert into [ptype]
([typeId], [Parid], [leveal], [soncount], [sonnum],
[FullName], [Name], [UserCode], [Standard], [Type],
[Area], [Unit1], [Unit2], [UnitRate1], [UnitRate2],
[preprice1], [preprice2], [UsefulLifeMonth],
[UsefulLifeDay], [Comment], [namepy], [parrec],
[Barcode])

values (@EtypeId_1, @Parid, @leveal, 0, 0,
@FullName, @Name, @UserCode, @Standard, @Type,
@Area, @Unit1, @Unit2, @UnitRate1, @UnitRate2,
@preprice1, @preprice2, @LifeMonth,
@LifeDay, @Comment, @namepy, @parrec,
@Barcode)

if @@rowcount=0
begin
ROLLBACK TRAN InsertP
Return -1
end
else
begin
Update [ptype]
set [sonnum]=@nSonnum+1,[soncount]=@nSoncount+1
Where [typeid]=@Parid
end

COMMIT TRAN InsertP

goto succee

succee:
Return 0

error111:
Return -1

error112:
Return -2

error113:
Return -3

error114:
Return -4
GO

 

///////////////////利用游标

IF len(@Parid)=25 RETURN -1
DECLARE @execsql [VARCHAR](500)
DECLARE @szTypeId VARCHAR(25),@sonnum INT,@par VARCHAR(25),@soncount INT
SELECT @execsql=' SELECT typeid,sonnum,parid,soncount FROM '
+@dbname+' WHERE typeid= '+''''+@parid+''''

DECLARE checkid_CURSOR CURSOR FOR
EXEC (@execsql)
OPEN checkid_CURSOR
FETCH NEXT FROM checkid_CURSOR INTO @szTypeId, @sonnum, @par,@soncount
WHILE (@@FETCH_STATUS = 0)
Begin
Set @nSon=@sonnum
Set @nCount=@soncount
DECLARE @tempId VARCHAR(5),@nReturn INT
Set @soncount=@soncount+1
EXEC @nReturn=inttostr @soncount,@tempId out
IF @nReturn=-1
BEGIN
CLOSE checkid_CURSOR
DEALLOCATE checkid_CURSOR
RETURN -2
END
ELSE
BEGIN
IF @sztypeid='00000'
Set @createdid=@tempId
ELSE
Set @createdid=RTRIM(@szTypeid)+@tempId
END
FETCH NEXT FROM checkid_CURSOR INTO @szTypeId, @sonnum, @par,@soncount
End
CLOSE checkid_CURSOR
DEALLOCATE checkid_CURSOR
RETURN 1

上一篇:Asp.Net中使用水晶报表 下一篇:用 C# 开发 SQL Server 2005 的自定义聚合函数
本栏目热门文章
·Windows XP下安装SQL2000企业版 2005-10-4
·"SQL Server不存在或访问被拒绝"问题的解决 2006-8-11
·在SQL Server 2000里设置和使用数据库复制 2005-11-13
·SQL中通配符、转义符与"["号的使用(downmoon) 2005-11-3
·SQL SERVER实用技巧 2005-11-3
·SQL Server 数据库管理常用的SQL和T-SQL语句 2005-11-13
·配置SQL Server 2000选项 2005-10-8
·Sql Server下数据库链接的使用方法 2005-11-21
·如何使Microsoft SQL Server的日志文件不会增大? 2005-10-4
·如何快速杀死占用过多资源(CPU,内存)的数据库进程 2005-11-13
新近更新文章
·MySQL将为数据库管理员减负 2006-12-7
·提数据高分页效率 2006-12-7
·MS SQL可写脚本和编程的扩展SSIS包 2006-12-7
·用SQL数据库批量插入数据简介 2006-12-7
·Microsoft Access技巧及陷阱讲解 2006-12-7
·深入浅出SQL教程之SELECT语句的自连接 2006-12-7
·在数据库里取前10条数据 2006-12-7
·恢复误删数据(SQL Server 2000)--Log Explo 2006-12-7
·页面中标题替换方法,在SQL中取数据时 2006-12-7
·深入浅出SQL之左连接、右连接和全连接 2006-11-26
首 页 | 软件发布 | 广告联系 | 下载帮助 | 意见反馈 | 网站地图
  CopyRight? 2002-2004 WWW.SXSKY.NET? All Rights Reserved
三湘时空 站长QQ:82675303 Email: