I would like to exec master..xp_fixeddrives which will give you the list of
physical drives sqlserver sees. Output is Drives, FreeSpace from
xp_fixeddrives.
I would like to write this information to a table with Drive,
FreeSpace,SampleTime.
The SampleTime will be the getdate() function.
Please help me with this issue.
ThanksCREATE TABLE #DriveData
(
Drive CHAR(2),
FreeSpace BIGINT,
SampleTime DATETIME NOT NULL DEFAULT GETDATE()
);
INSERT #DriveData
(
Drive,
FreeSpace
)
EXEC master..xp_fixeddrives;
SELECT Drive, FreeSpace, SampleTime
FROM #DriveData;
DROP TABLE #DriveData;
"Joe K." <Joe K.@.discussions.microsoft.com> wrote in message
news:23A81366-D8DD-4833-B25C-96DF0561090D@.microsoft.com...
>I would like to exec master..xp_fixeddrives which will give you the list of
> physical drives sqlserver sees. Output is Drives, FreeSpace from
> xp_fixeddrives.
> I would like to write this information to a table with Drive,
> FreeSpace,SampleTime.
> The SampleTime will be the getdate() function.
> Please help me with this issue.
> Thanks
>
>|||CREATE TABLE #diskspace(
drivename VARCHAR(50),
MBFree INT)
INSERT INTO #diskspace(drivename,MBFree) exec master..xp_fixeddrives
SELECT * FROM #diskspace|||CREATE TABLE #diskspace(
drivename VARCHAR(50),
MBFree INT)
INSERT INTO #diskspace(drivename,MBFree) exec master..xp_fixeddrives
SELECT * FROM #diskspace|||Note the addition of the date field to the table.
CREATE TABLE #diskspace(
drivename VARCHAR(50),
MBFree INT,
sampledate DATETIME default getdate()
)sql
Showing posts with label exec. Show all posts
Showing posts with label exec. Show all posts
Wednesday, March 21, 2012
Wednesday, March 7, 2012
GET STORED PROCEDURE RESULT SET TO TEMP TABLE
I wanted to insert stored procedure result into my temp table.
I tried 'SELECT * INTO FROM EXEC MYPROC @.MYPARAM = 1', but it does not work.
any information is great appreciated,Hi
You can try this way
INSERT INTO #tempTable EXEC MYPROC @.MYPARAM = 1
best Regards,
Chandra
http://chanduas.blogspot.com/
---
"Souris" wrote:
> I wanted to insert stored procedure result into my temp table.
> I tried 'SELECT * INTO FROM EXEC MYPROC @.MYPARAM = 1', but it does not wor
k.
> any information is great appreciated,
>
I tried 'SELECT * INTO FROM EXEC MYPROC @.MYPARAM = 1', but it does not work.
any information is great appreciated,Hi
You can try this way
INSERT INTO #tempTable EXEC MYPROC @.MYPARAM = 1
best Regards,
Chandra
http://chanduas.blogspot.com/
---
"Souris" wrote:
> I wanted to insert stored procedure result into my temp table.
> I tried 'SELECT * INTO FROM EXEC MYPROC @.MYPARAM = 1', but it does not wor
k.
> any information is great appreciated,
>
Sunday, February 26, 2012
Get result from EXEC()
I currently do this:
INSERT INTO #tbl2 EXEC(@.sql)
IF @.@.ROWCOUNT = 1
INSERT INTO @.tbl3 SELECT userID FROM #tbl2
DELETE FROM #tbl2
Is there any other way to recieve the result from column userid from the @.sql-query?Hi,
try to use sp_executesql (see BOL):
sp_executesql [@.stmt =] stmt
[
{, [@.params =] N'@.parameter_name data_type [,...n]' }
{, [@.param1 =] 'value1' [,...n] }
]
Markus|||How do you mean?|||Hi,
i don't know what you really want to query, but here an (quick and dirty) example:
-- testing enviroment
create table usernames( userid int, username varchar(100) )
insert into usernames (userid,username) values ( 123, 'moby' )
insert into usernames (userid,username) values ( 986, 'lars' )
-- select * from usernames
--
-- vars
declare @.Stmt nvarchar(200), @.UserID int, @.UserName varchar(100)
-- SQL-Stattement to get result from
select @.Stmt='select @.P1= userid from usernames where username=@.P2'
-- "input" parameter
select @.Username='moby'
-- query result
exec sp_executesql @.Stmt, N'@.P1 int output, @.P2 varchar(100)', @.P1=@.UserID output, @.P2=@.Username
-- show result
print @.Username
print @.UserID
-- get rid of testdata
drop table usernames|||Thank you!
INSERT INTO #tbl2 EXEC(@.sql)
IF @.@.ROWCOUNT = 1
INSERT INTO @.tbl3 SELECT userID FROM #tbl2
DELETE FROM #tbl2
Is there any other way to recieve the result from column userid from the @.sql-query?Hi,
try to use sp_executesql (see BOL):
sp_executesql [@.stmt =] stmt
[
{, [@.params =] N'@.parameter_name data_type [,...n]' }
{, [@.param1 =] 'value1' [,...n] }
]
Markus|||How do you mean?|||Hi,
i don't know what you really want to query, but here an (quick and dirty) example:
-- testing enviroment
create table usernames( userid int, username varchar(100) )
insert into usernames (userid,username) values ( 123, 'moby' )
insert into usernames (userid,username) values ( 986, 'lars' )
-- select * from usernames
--
-- vars
declare @.Stmt nvarchar(200), @.UserID int, @.UserName varchar(100)
-- SQL-Stattement to get result from
select @.Stmt='select @.P1= userid from usernames where username=@.P2'
-- "input" parameter
select @.Username='moby'
-- query result
exec sp_executesql @.Stmt, N'@.P1 int output, @.P2 varchar(100)', @.P1=@.UserID output, @.P2=@.Username
-- show result
print @.Username
print @.UserID
-- get rid of testdata
drop table usernames|||Thank you!
Subscribe to:
Posts (Atom)