Domanda

I have an insert statement that inserts events into a table. I need it to NOT insert if these events contain specific words or even specific username executing the event. Thought this would be easy but it's not working at all. Tried different techniques including adding the if statement before the insert but no go something like this

IF SUSER_SNAME() not like '%someuser%' OR CURRENT_USER NOT like '%anotheruser%' Begin INSERT DBA_DB.dbo.Events (...) Select Events END

tried different variations but cannot filter inserts. So many example online but they are all referring to NOT EXISTS when checking a value already in the table. I need to check the values of events, filter them out, and then insert.

Any thoughts? Thanks

SQL2014

È stato utile?

Soluzione

Try changing your OR to AND - IF SUSER_SNAME() not like '%someuser%' AND CURRENT_USER NOT like '%anotheruser%'.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a dba.stackexchange
scroll top