Solved

Save result of sp_who in a table with inserted date

Posted on 2006-11-08
3
1,030 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

630 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