论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > asp教程
Tag:入门,文摘,实例,技巧,iis,表单,对象,上传,数据库,记录集,session,cookies,存储过程,注入,分页,安全,优化,xmlhttp,fso,jmail,application,防盗链,stream,组件,md5,乱码,缓存,加密,验证码,算法,ubb,正则表达式,水印,,日志,压缩,url重写,控件,函数,破解,触发器,socket,ADO,初学,聊天室,留言本,视频教程

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

文章类别:asp | 发表日期:2008-10-5 20:55:11

加贴存储过程:
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<>'swuse@21cn.com 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
视频教程列表
文章教程搜索
 
Asp推荐教程
Asp热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058