I am attempting to create my first SQL Audit and I've ran into a bit of a snag. I have two tables, a temp table that has the Audit log, and a table with Lastnames (lets call it tblLastName).
Now, the audit is against anything with a SELECT against specific tables and I want to take the results and compare them with my Last Name table. Basically, in the Audit table is the statement column, in there will be something similar to
DELETE FROM member WHERE team_identifier = 1
DELETE FROM member WHERE team_identifier = 2
DELETE FROM player
WHERE Identifier NOT IN (SELECT player_identifier FROM member)
How might I go about getting just the value between the % % to compare it against the lastnames table.
At the moment I can get which rows have a last name selected against, but I do not know how to turn that into anything useful. My logic I thought would work would be to get the rows that have a last name, get the substring (which is where i am stuck) of that row to get just the name, store that name in a variable, and then compare against the other table. Unfortunately all I have so far is:
where lastname like %personslastname%
Any help would be appreciated. Also it is SQL Server 2008.
Edit for data:
select * from #MyTempTable where statement like '%LastName like%'
produces results like: Super User, Hendrix, Greenwood, Page,
My Audit Statement is much more in depth though so I've taken a bit out:
SELECT vLastName from tblLastName