当前位置: 首页 > 图文教程 > 网络编程 > ASP > 用排序串字段实现树状结构(存储过程)

ASP
BytesToBstr获取的源码转换为中文的代码
PostHttpPage用asp是实现模拟登录效果的代码
asp下实现UrlEncoding转换编码的代码
GetBody asp实现截取字符串的代码
asp之GetArray提取链接地址,以$Array$分隔的代码
DefiniteUrl asp将相对地址转换为绝对地址的代码
ReplaceSaveRemoteFile 替换、保存远程图片 的代码
ReSaveRemoteFile函数之asp实现查找文件保存替换的代码
FormatRemoteUrl函数之asp实现格式化成当前网站完整的URL-将相对地址转换为绝对地址的代码
ReplaceTrim 函数之asp实现过滤掉字符中所有的tab和回车和换行的代码
CheckFile函数之asp实现检查某一文件是否存在的代码
SaveRemoteFile函数之asp实现保存远程的文件到本地的代码
FpHtmlEnCode 函数之标题过滤特殊符号的代码
GetPaing 函数之asp采集函数中用到的获取分页的代码
ScriptHtml 函数之过滤html标记的asp代码
asp实现检查目录是否存在与建立目录的函数
ShowPage 显示“上一页 下一页”等信息的封装代码
JoinChar 向地址中加入 ? 或 & 用于实现传参
CreateKeyWord asp实现的由给定的字符串生成关键字的代码
Server.Execute方法执行指定的ASP程序

ASP 中的 用排序串字段实现树状结构(存储过程)


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

  加贴存储过程:
if exists (select * from sysobjects where id = object_id("lybsave"))
   drop proc lybsave
CREATE PROCEDURE [lybsave] @keyid int=0,@guestname varchar(20),@guestitle varchar(100),@guestcomm
text,@guestemail varchar(50)='',@emailflag bit=0,@fromip varchar(15),@recimail varchar(50) OUTPUT
AS
DECLARE @ostr varchar(30),@rootid int,@lybid int,@ostrs varchar(30),@l tinyint,@tdt datetime,@putdate
varchar(10),@puttime varchar(5),@eflag bit
select @tdt=getdate()
select @putdate=convert(varchar(4),datepart(yy,@tdt))+'-'+left('0'+convert(varchar(2),datepart(mm,@tdt)),2)
+'-'+left('0'+convert(varchar(2),datepart(dd,@tdt)),2)
select @puttime=left('0'+convert(varchar(2),datepart(hh,@tdt)),2)+':'+left('0'+convert(varchar(2),datepart
(mi,@tdt)),2)
select @ostr='',@rootid=0,@lybid=0,@l=0
if (@guestemail='') select @emailflag=0
If @keyid=0  --发新贴
  goto newin
ELSE
begin
  SELECT @lybid=lybid,@rootid=rootid,@ostr=orderstr,@recimail=guestemail,@eflag=emailflag from guestbook
where lybid=@keyid
  IF @lybid=0  --回复贴没找到,当新贴发表
   goto newin
  ELSE
   BEGIN
    if (@eflag=0 and @guestemail<>'[email protected] abc') select @recimail=''  --如果是版主回复且指定发邮件给提
问者,则不管发贴者是否要求回复,后面的abc相当于管理密码
    if (@rootid=0) select @rootid=@lybid
    select @ostrs=@ostr+'%',@lybid=0
    select top 1 @lybid=lybid,@ostrs=orderstr from guestbook where rootid=@rootid and (orderstr like
@ostrs) and lybid<>@keyid order by orderstr
    if (@lybid=0) select @ostr=@ostr+char(122)
    else
     begin
      select @l=len(@ostrs)
      select @ostr=left(@ostrs,@l-1)+char(ascii(substring(@ostrs,@l,1))-1)
     end
    goto newin
   end
end

newin:
    INSERT into guestbook
(guestname,guestitle,guestcomm,putdate,puttime,guestemail,emailflag,rootid,fromip,orderstr) values
(@guestname,@guestitle,@guestcomm,@putdate,@puttime,rtrim(@guestemail),@emailflag,@rootid,@fromip,@ostr)

删贴(剪枝)存储过程:

if exists (select * from sysobjects where id = object_id("lybdel"))
   drop proc lybdel
CREATE PROCEDURE [lybdel] @keyid int
AS
DECLARE @ostr varchar(30),@rootid int,@lybid int
select @ostr='',@rootid=0,@lybid=0
SELECT @ostr=orderstr,@rootid=rootid,@lybid=lybid from guestbook where lybid=@keyid
if (@lybid<>0)
  BEGIN
    if (@rootid=0) select @rootid=@lybid
    SELECT @ostr=@ostr+'%'
    DELETE FROM guestbook where orderstr like @ostr and rootid=@rootid or lybid=@rootid
  END