Hi
I'm using SQL 2005 and trying to find a way to track when users are including specific criteria in their SQL queries. I'm trying to avoid implementing RLS because I think that would have it's own set of headaches.
I'm able to get the info below if I run manually throughout the day.
select
getdate() datestamp
,db_name(database_id)db
,r.start_time,
s.session_id
,s.[status] session_status,
substring(t.text,(r.statement_start_offset/2)+1,
case when statement_end_offset=-1 or statement_end_offset = 0
then (datalength(t.[text])-r.statement_start_offset/2)+1
else (r.statement_end_offset-r.statement_start_offset)/2+1 end) Query,
command,
wait_type,
wait_time,
wait_resource,
last_wait_type
,original_login_name
,login_time
,charindex('CP',t.text)CP_char
,program_name prog_name
,charindex(where_clause,t.text)
,where_clause
,user_id
--into G7_audit
from sys.dm_exec_sessions s left outer join sys.dm_exec_requests r on s.session_id = r.session_id
outer apply sys.dm_exec_sql_text(sql_handle)t
left outer join g7_audit_phrase g7 on charindex(where_clause,t.text)>0
--
where s.session_id<>@@spid
and charindex('abstract',t.text)=0 and (charindex(where_clause,t.text)>0 or charindex(' CP',t.text)>0 or charindex('%CP',t.text)>0) and user_id not in (13,20,267) and is_member('db_datareader')=
All help is greatly appreciated!
Thanks
Katie