Multiple deletes from table

Christopher Jack 1,616 Reputation points
2021-02-28T20:27:21.53+00:00

Hi,

I am wanting to delete mulitple rows, what is rthe best way to go about it.

I currently have

DELETE FROM FactPayment WHERE paymentid 
in ('D1542607',
'D1543109',
'D1543201',
'D2374',
'D255970,'
'D375312',
'D394066',
'D406957',
'D637556',
'D637586',
'D638528',
'D643587',
'D644033',
'D646431',
'D726488',
'D732753',
'D740707',
'D773051',
'D778278',
'D801801',
'D810586',
'D854640',
'D883180',
'D883182',
'D885657',
'D903554',
'D904115',
'D915909',
'D947576',
'D964769',
'D971828')
and CustomerKey is null;

But that doesn seem to work.. error message is

Msg 102, Level 15, State 1, Line 7
Incorrect syntax near 'D375312'.

Any help appreciated.

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,580 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Joe Celko 16 Reputation points
    2021-02-28T22:50:36.397+00:00

    The immediate answer is that you got a quote mark out of place. But your code actually shows some other problems. In a properly designed schema, there would never be a column named anything like "<attribute>_key" under the ISO 11179 naming rules. You're supposed to named data elements by what they are and not by how they are used for. Those postfixes are called attribute properties and they cannot represent metadata. Separation of data from metadata is one of the fundamentals of RDBMS.