MCITP

MCITP

Thursday, March 10, 2011

SP_WHO@_DB Procedure

sp_who2_db 'staf'
create PROCEDURE sp_who2_db(@dbname varchar(100))
AS
BEGIN
IF object_id('tab1') IS NOT NULL
DROP TABLE tab1
CREATE TABLE tab1( i1 varchar(1000),i2 varchar(1000),i3 varchar(1000),i4 varchar(1000),
i5 varchar(1000),i6 varchar(1000),i7 varchar(1000),i8 varchar(1000),
i9 varchar(1000),i10 varchar(1000),i11 varchar(1000),
i12 varchar(1000),i13 varchar(1000))

INSERT INTO tab1
EXEC ('sp_who2 ')
SET @dbname = '%' + @dbname +'%'
SELECT * FROM tab1 WHERE i6 LIKE @dbname
END

No comments:

Post a Comment