Solved

Save result of sp_who in a table with inserted date

Posted on 2006-11-08
3
1,003 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
Comment Utility
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
Comment Utility
you create the column with the default detdate(), but then don't specify it in the values list.
0
 

Author Comment

by:kdunnett
Comment Utility
Thanks!

Kris
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

763 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

12 Experts available now in Live!

Get 1:1 Help Now