stumit63
stumit63

Reputation: 61

Delete Fails using ODBC in SSIS

I changed an Execute SQL Task targeting my default, local SQL Server instance from OLE DB to ODBC. The SQL is

delete from tablename

The ODBC version works fine when the table has records but fails when the table is empty.

I thought about using the result set of another SQL Task to populate a variable but that would not work. Reading this SO article Delete statement fails when called from SSIS identified the source of the problem (ODBC version), but it still didn't provide the answer. Other web articles suggested no workaround.

Are there any other methods or approaches to conditionally call the delete only if the table is not empty?.

Upvotes: 1

Views: 346

Answers (1)

stumit63
stumit63

Reputation: 61

It occurred to me to just use T-SQL to solve the problem. I used a T-SQL conditional statement which works fine. The ODBC SQL Task succeeds whether or not the table is empty.

if 0 < (select count(1) from tablename)
delete from tablename

Upvotes: 0

Related Questions