Solved

Save result of sp_who in a table with inserted date

Posted on 2006-11-08
3
1,013 Views
Last Modified: 2008-02-01
All,

I created a table that matches the structure of sp_who:

table tbl_sp_who:
  spid            smallint,
  ecid            smallint,
  status            nchar(30),
  loginame            nchar(128),
  hostname      nchar(128),
  blk            char(5),
  dbname            nchar(128),
  cmd            nchar(16)

When you execute the below insert statement:
insert into tbl_sp_who execute sp_who

It saves the result into the table...

NOW, I want to add a column "insertDate" where when a record goes in, it has a time stamp of when it goes it.  This way I can look at the table like a log.

How do I do it?  I tried adding the extra column and going the 'getDate()' route but just adding the extra column crashes the insert statement.  

Any ideas?

Thanks in advance,
kris
0
Comment
Question by:kdunnett
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
Nightman earned 500 total points
ID: 17901106
create table  tbl_sp_who
(
  spid          smallint,
  ecid          smallint,
  status          nchar(30),
  loginame          nchar(128),
  hostname     nchar(128),
  blk          char(5),
  dbname          nchar(128),
  cmd          nchar(16),
  insertdate datetime default(getdate())
)

insert into tbl_sp_who (spid,ecid,status,loginame,hostname,blk,dbname,cmd)
exec sp_who
0
 
LVL 29

Expert Comment

by:Nightman
ID: 17901112
you create the column with the default detdate(), but then don't specify it in the values list.
0
 

Author Comment

by:kdunnett
ID: 17901400
Thanks!

Kris
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now