<pre>
use sybsystemprocs
go

if exists (select * from sysobjects where name = "sp_showuser" and type = 'P')
   drop proc sp_showuser
go

create procedure sp_showuser @loginame varchar(30) = NULL 
as

-- Customized version of sp_who by Teresa Larson, tlarson@ari.net

declare @low int
declare @high int
declare @spidlow int
declare @spidhigh int

select @low = 0, @high = 32767, @spidlow = 0, @spidhigh = 32767

if @loginame is not NULL
begin
        select @low = suser_id(@loginame), @high = suser_id(@loginame)
        if @low is NULL
        begin
                if @loginame like "[0-9]%"
                begin
                        select @spidlow = convert(int, @loginame),
                             @spidhigh = convert(int, @loginame),
                             @low = 0, @high = 32767
                end
                else
                begin
                        print "No login exists with the supplied name."
                        return (1)
                end
        end
end

DECLARE @showdate char(30)

select @showdate = getdate()

PRINT " " 
PRINT @showdate
PRINT " "

select spid,status,loginame=substring(suser_name(suid),1,12),
   program_name,
   dbname=substring(db_name(dbid),1,10),cmd
from master.dbo.sysprocesses
where suid >= @low and suid <= @high
and spid >= @spidlow and spid <= @spidhigh

return (0)
go

grant execute on sp_showuser to public
go 
