drop procedure GetWindows
go
create procedure GetWindows(@origin varchar(10))
as 
declare @i int,
@windows varchar(100),
@workid varchar(4)
set @workid=''
set @windows=''
declare win_cur scroll cursor
for select workid  from window where place=@origin group by workid
open win_cur
if @@cursor_rows>0
begin
set @i=1
while @i<=@@cursor_rows
begin
fetch next from win_cur into @workid
if @windows=''
set @windows=cast(@workid as char(4))
else
set @windows=@windows+','+cast(@workid as char(4))
set @i=@i+1

end end
close win_cur
deallocate win_cur
select @windows

解决方案 »

  1.   

    更简单的方法:drop procedure GetWindows
    go
    create procedure GetWindows(@origin varchar(10))
    as 
    declare @windows varchar(100)
    set @windows=''
    select @windows=@windows+','+CAST(workid AS VARCHAR(4))  from window where place=@origin group by workid
    SET @windows=SUBSTRING(@windows,2,LEN(@windows)-1)
    Select @windows
    GO