Solved

Save result of sp_who in a table with inserted date

Posted on 2006-11-08
3
1,009 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

911 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

21 Experts available now in Live!

Get 1:1 Help Now