I am running into some odd behavior with a step in a DTS package. The step is an execute SQL task. Here's the issue:

When I execute the following SQL in Query Analyzer, it runs just fine with no errors. When I execute the task using the exact same SQL, it errors out. Here's the SQL:

DECLARE @aimqueryid INTEGER,
@aimconnectionid INTEGER,
@servicetypeid INTEGER,
@gooditemscount INTEGER,
@sorryitemscount INTEGER,
@aimqueryreceipt DATETIME,
@aimqueryresponse DATETIME,
@errorseverity INTEGER,
@errortype VARCHAR(24),
@errormessage VARCHAR(256),
@failurecode INTEGER

DECLARE aimquery_cursor CURSOR FOR
SELECT AIMQUERYID,
AIMCONNECTIONID,
SERVICETYPEID,
GOODITEMSCOUNT,
SORRYITEMSCOUNT,
AIMQUERYRECEIPT,
AIMQUERYRESPONSE,
ERRORSEVERITY,
ERRORTYPE,
ERRORMESSAGE,
FAILURECODE
FROM AIMQUERY_AUDIT
WHERE ACTION_TYPE = 'U'
ORDER BY AIMQUERYID

OPEN aimquery_cursor
FETCH NEXT FROM aimquery_cursor
INTO
@aimqueryid,
@aimconnectionid,
@servicetypeid, <---- LINE 16
@gooditemscount,
@sorryitemscount,
@aimqueryreceipt,
@aimqueryresponse,
@errorseverity,
@errortype,
@errormessage,
@failurecode
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE AIMQUERY SET
AIMQUERYID = @aimqueryid,
AIMCONNECTIONID = @aimconnectionid,
SERVICETYPEID = @servicetypeid,
GOODITEMSCOUNT = @gooditemscount,
SORRYITEMSCOUNT = @sorryitemscount,
AIMQUERYRECEIPT = @aimqueryreceipt,
AIMQUERYRESPONSE = @aimqueryresponse,
ERRORSEVERITY = @errorseverity,
ERRORTYPE = @errortype,
ERRORMESSAGE = @errormessage,
FAILURECODE = @failurecode
WHERE AIMQUERYID = @aimqueryid

FETCH NEXT
FROM aimquery_cursor
INTO @aimqueryid,
@aimconnectionid,
@servicetypeid,
@gooditemscount,
@sorryitemscount,
@aimqueryreceipt,
@aimqueryresponse,
@errorseverity,
@errortype,
@errormessage,
@failurecode
END
CLOSE aimquery_cursor
DEALLOCATE aimquery_cursor

I get the following error:

DEFERRED PREPARE COULD NOT BE COMPLETED
LINE 16: INCORRECT SYNTAX NEAR ','

What is the deal here? Like I mentioned earlier, this runs fine in Query Analyzer but the Execcute SQL task in DTS doesn't like this.

Any help wold be great.

Thanks!