Multiple DELETE statements in a single query in Cache Monitr
I need to execute multiple DELETE statements in a single query like this
DELETE FROM TableName WHERE ID = 2;
DELETE FROM TableName WHERE ID = 3;
DELETE FROM TableName WHERE ID = 4;However It does not work when there're more than 2 statements and gives me an error
Expected FROM found WHERE^DELETE FROM TableName WHERE
Using IN is not an option.
Comments
what about simply using OR in your SQL:
DELETE FROM TableName WHERE ID = 2
OR ID = 3
OR ID = 4
OR <whaever condition>
OR <whaever other condition>
BUT: if you intend to have tablename1, tablename2, tablename3, ...
you better wrap it in a ClassMethod and project it as Stored Procedure
Then there would be 70 000 OR conditions.
So put it in a Stored procedure and deposit the conditions in a table.
Could be a classical case to use indirection or eXecute
Whether maintaining a table or 70000 different WHERE should be the same effort.
At that point: Why to use SQL DELETE at all ?
Because I know for a fact that is possible to have multiple statements within a single query, but Monitor does not like it right know and I need to figure out why, because Cache errors are as uninformative as it gets, so I am forced to ask here.
It's a one-time task and I can't be bothered to create new tables and procedures for it.
"know for a fact that is possible to have multiple statements within a single query"
I wasn't aware of such a feature over the decades.
So it might be wise to get in contact with your personal Sales Engineer or contact WRC
It should be like this (see Work with multiple sql statements):
<FONT COLOR="#0000ff">DELETE </FONT><FONT COLOR="#000080">FROM </FONT><FONT COLOR="#008000">TableName </FONT><FONT COLOR="#000080">WHERE </FONT><FONT COLOR="#008000">ID </FONT><FONT COLOR="#000000">= 2</FONT> GO <FONT COLOR="#0000ff">DELETE </FONT><FONT COLOR="#000080">FROM </FONT><FONT COLOR="#008000">TableName </FONT><FONT COLOR="#000080">WHERE </FONT><FONT COLOR="#008000">ID </FONT><FONT COLOR="#000000">= 3</FONT> GO <FONT COLOR="#0000ff">DELETE </FONT><FONT COLOR="#000080">FROM </FONT><FONT COLOR="#008000">TableName </FONT><FONT COLOR="#000080">WHERE </FONT><FONT COLOR="#008000">ID </FONT><FONT COLOR="#000000">= 4</FONT> GO
Does 'GO' have to be on a new line? Because I tried to place it on the same line as the query and recieved an error