Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

MS SQL Create Table through Stored Procedure

$
0
0

I have created a stored procedure that pulls sp_who2 information to a table, "myTable" for running queries against. When this stored procedure is called through SSRS by a end user to see who is in the database prior to creating a manual backup. It is creating the table; however, it is assigning it to a different schema. It is creating the table as domain\user.myTable.

Is there any way to get it to create just the table as "myTable" instead of the domain\user.myTable?

Here is the code for the stored procedure. Thanks in advance.

GO
ALTER Procedure [dbo].[WhoIsInCareKeeper]
(
@databaseName sysname
)
AS
BEGIN

CREATE TABLE myTable (
spid int
, ecid int
, status varchar(50)
, loginame varchar(255)
, hostname varchar(255)
, blk varchar(50)
, dbname varchar(255)
, cmd varchar(255)
, requestid int
)


INSERT INTO myTable EXEC sp_who

SELECT DISTINCT loginame, dbname, hostname FROM myTable
WHERE dbname = @databaseName


DROP TABLE myTable

END


Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>