Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Auditing as part of select statemet

Author  Topic 

learntsql

524 Posts

Posted - 2010-03-29 : 09:29:21
Hi All,
How to capture where condition trace as part of select statement it self.
for eg;

select *
from emp
where ISExpired IS NOT NULL
...

Now i want to insert one trace record into Audit table as ISExpired is null
Can we capture as part of select statement or any other way.
Sorry if i am not clear.
TIA.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-29 : 11:42:58
Sorry you're not clear. which audit table you are talking about? explain with an example

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

learntsql

524 Posts

Posted - 2010-03-30 : 00:59:38
let me explain.

i have table called Employee (Eno,Ename,Designation,Deptno,ISExpired,Age).
i am performing select operation on this table as like
CREATE PROC proc_ReadEmpData
(
@EmpNo int,
@Age int,
@Desig varchar(50)
)
AS
BEGIN
select *
from Employee
WHERE ISExpired IS NOT NULL
ANd EmpNo = @EmpNo
AND Age=@Age
AND Designation = @Desig
END

--EXEC proc_ReadEmpData 101,25,'Admin'

When i execute this procedure i pass the above values as parameters.
for this employee ISExpired value is null
That I want to capture and store/insert into on of the tracing(user defined) tables under remarks column as ISExpired is null(for eg;)
similer to this i use few more filters in WHERE clause and all i want to capture into tracing table.
TIA.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-30 : 13:16:27
for capturing this info dump the above select's resultset to your table using INSERT...SELECT

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -