写了一个存储过程,不知道哪错了!请高手指点一下吧,谢谢了!
CREATE PROCEDURE Role_GetMembers
@roleid int
asdeclare @str nvarchar(500)
declare user_cursor cursor for
select userid from userinrole where roleid = @roleidopen user_cursorfetch next from user_cursor into @str
while @@fetch_status = 0
begin
set @str = @str + ','
end
close user_cursor
deallocate user_cursor
select * from users where [id] in (@str)go其中,userid字段为INT类型。
CREATE PROCEDURE Role_GetMembers
@roleid int
asdeclare @str nvarchar(500)
declare user_cursor cursor for
select userid from userinrole where roleid = @roleidopen user_cursorfetch next from user_cursor into @str
while @@fetch_status = 0
begin
set @str = @str + ','
end
close user_cursor
deallocate user_cursor
select * from users where [id] in (@str)go其中,userid字段为INT类型。
select * from users where charindex(',' + [id] + ',', ',' + @str + ',')>0
set @str =''
@roleid int
as
select * from users where [id] in(
select userid from userinrole where roleid = @roleid)
@roleid int
asdeclare @str nvarchar(500)
set @str=',-1'
declare @userid int
declare user_cursor cursor for
select userid from userinrole where roleid = @roleidopen user_cursorfetch next from user_cursor into @userid
while @@fetch_status = 0
begin
set @str = @str + ',' + @userid
fetch next from user_cursor into @userid
end
close user_cursor
deallocate user_cursorset @str=stuff(@str, 1, 1, '')
select * from users where [id] in (@str)go