declare @fid int,@i int, @name varchar(500),@str varchar(1000),@n int,@id int,@j int
set @id = 97
select @j = fatherid , @name = [name] from menu_tree where id=@id 
set @i = @jset @str = 'docFile/'while @i>0
begin
  set @n = charindex('/',@str)
  set @str =  left(@str,@n) + @name + '/' + right(@str,(len(@str)-@n))
  select @j = fatherid , @name = [name] from menu_tree where id=@i
  set @i = @j
endif(@i=0)
begin
set @n = charindex('/',@str)
set @str = left(@str,@n) + @name + '/' + right(@str,(len(@str)-@n))
endprint @str

解决方案 »

  1.   

    create proc Identity
    @Id int,
    @Out output
    if @id=4
     set @Out='docfile/a/b/c/d/'
    else
     ....是这样吗?
     
      

  2.   

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go
    alter PROCEDURE [dbo].[check]
    as 
    begin 
    declare mycur cursor for select id from product
    declare @id int
    declare @Msg varchar(30)
    open mycur 
    fetch next from mycur into @id
    while (@@fetch_status=0) 
    begin
    if(@id=4)
    begin
    set @Msg='docfile/a/b/c/d/'
    end
    fetch next from mycur into @id
    end
    close mycur
    deallocate mycur
    return @Msg
    end