I am getting the following error statement when running a SSIS package. My statement includes<\/p>\n
FROM [tablename] WITH(nolock)<\/p>\n
Whenever I parse, it says it’s valid but it fails in the Pre-execute stage. Does anyone know what I am doing wrong?<\/p>\n
Messages
\nError 0xc0202009: Data Flow Task 1: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E14.
\nAn OLE DB record is available. Source: “Microsoft SQL Server Native Client 11.0” Hresult: 0x80040E14 Description: “Case expressions may only be nested to level 10.”.
\nAn OLE DB record is available. Source: “Microsoft SQL Server Native Client 11.0” Hresult: 0x80040E14 Description: “Incorrect syntax near the keyword ‘with’. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.”.
\nAn OLE DB record is available. Source: “Microsoft SQL Server Native Client 11.0” Hresult: 0x80040E14 Description: “Statement(s) could not be prepared.”.
\n(SQL Server Import and Export Wizard)<\/p>","upvoteCount":4,"answerCount":13,"datePublished":"2018-08-09T10:14:26.000Z","author":{"@type":"Person","name":"ryangee","url":"https://community.spiceworks.com/u/ryangee"},"suggestedAnswer":[{"@type":"Answer","text":"
I am getting the following error statement when running a SSIS package. My statement includes<\/p>\n
FROM [tablename] WITH(nolock)<\/p>\n
Whenever I parse, it says it’s valid but it fails in the Pre-execute stage. Does anyone know what I am doing wrong?<\/p>\n
Messages
\nError 0xc0202009: Data Flow Task 1: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E14.
\nAn OLE DB record is available. Source: “Microsoft SQL Server Native Client 11.0” Hresult: 0x80040E14 Description: “Case expressions may only be nested to level 10.”.
\nAn OLE DB record is available. Source: “Microsoft SQL Server Native Client 11.0” Hresult: 0x80040E14 Description: “Incorrect syntax near the keyword ‘with’. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.”.
\nAn OLE DB record is available. Source: “Microsoft SQL Server Native Client 11.0” Hresult: 0x80040E14 Description: “Statement(s) could not be prepared.”.
\n(SQL Server Import and Export Wizard)<\/p>","upvoteCount":4,"datePublished":"2018-08-09T10:14:26.000Z","url":"https://community.spiceworks.com/t/sql-ssis-question/666787/1","author":{"@type":"Person","name":"ryangee","url":"https://community.spiceworks.com/u/ryangee"}},{"@type":"Answer","text":"
I’ve not had any of those errors. In any case, you would want to start by looking at the first error thrown, not the last.<\/p>\n
Do you have more than 9 levels of nested case statements? I would guess you don’t. Presuming that is correct, I would expect that there’s a statement that’s not properly closed causing the cascade of errors.<\/p>","upvoteCount":0,"datePublished":"2018-08-09T11:17:53.000Z","url":"https://community.spiceworks.com/t/sql-ssis-question/666787/2","author":{"@type":"Person","name":"dsentelle","url":"https://community.spiceworks.com/u/dsentelle"}},{"@type":"Answer","text":"
I don’t. The query runs just fine for me outside of SSIS.<\/p>","upvoteCount":0,"datePublished":"2018-08-09T11:26:51.000Z","url":"https://community.spiceworks.com/t/sql-ssis-question/666787/3","author":{"@type":"Person","name":"ryangee","url":"https://community.spiceworks.com/u/ryangee"}},{"@type":"Answer","text":"
Post your code (sanitized as needed) so we can have a look.<\/p>","upvoteCount":2,"datePublished":"2018-08-09T11:56:32.000Z","url":"https://community.spiceworks.com/t/sql-ssis-question/666787/4","author":{"@type":"Person","name":"larryshanahan","url":"https://community.spiceworks.com/u/larryshanahan"}},{"@type":"Answer","text":"
I would triple check that the code in SSIS is actually the code you’re running. More than once when developing our SSIS stuff I found I didn’t have exactly the code I’d expected pasted into the SSIS package.<\/p>\n
There’s some reason it thinks there’s a nested case statement. In my experience I’ve not had the SQL server tell me something that was wrong. Misleading, yes. Wrong, no.<\/p>","upvoteCount":1,"datePublished":"2018-08-09T12:39:38.000Z","url":"https://community.spiceworks.com/t/sql-ssis-question/666787/5","author":{"@type":"Person","name":"dsentelle","url":"https://community.spiceworks.com/u/dsentelle"}},{"@type":"Answer","text":"
This could also be due to the “linked server problem” pointed out by Aaron Bertrand<\/a> and Paul White<\/a> where a CASE statement gets re-written by the parser into nested form when sending it to a linked server.<\/p>","upvoteCount":1,"datePublished":"2018-08-09T12:51:41.000Z","url":"https://community.spiceworks.com/t/sql-ssis-question/666787/6","author":{"@type":"Person","name":"larryshanahan","url":"https://community.spiceworks.com/u/larryshanahan"}},{"@type":"Answer","text":" Here is the code… I removed my case statement and was still having issues with it…<\/p>","upvoteCount":0,"datePublished":"2018-08-09T13:11:34.000Z","url":"https://community.spiceworks.com/t/sql-ssis-question/666787/7","author":{"@type":"Person","name":"ryangee","url":"https://community.spiceworks.com/u/ryangee"}},{"@type":"Answer","text":" I could easily see that CASE getting parsed to a nested one. Could be something similar with the IN clause.<\/p>\n The table doesn’t have the school name? Seems odd.<\/p>","upvoteCount":0,"datePublished":"2018-08-09T13:23:24.000Z","url":"https://community.spiceworks.com/t/sql-ssis-question/666787/8","author":{"@type":"Person","name":"larryshanahan","url":"https://community.spiceworks.com/u/larryshanahan"}},{"@type":"Answer","text":" Removing the case statement didn’t resolve my issue. I was still getting error: “Incorrect syntax near the keyword ‘with’. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.”.<\/p>\n What’s confusing to me is I set up about 3 others with the same with(nolock) and had no issues.<\/p>","upvoteCount":0,"datePublished":"2018-08-09T13:26:41.000Z","url":"https://community.spiceworks.com/t/sql-ssis-question/666787/9","author":{"@type":"Person","name":"ryangee","url":"https://community.spiceworks.com/u/ryangee"}},{"@type":"Answer","text":" It does have school names but I had to change them to match my import… The place I am importing the files to do not have our correct school names.<\/p>","upvoteCount":0,"datePublished":"2018-08-09T13:29:13.000Z","url":"https://community.spiceworks.com/t/sql-ssis-question/666787/10","author":{"@type":"Person","name":"ryangee","url":"https://community.spiceworks.com/u/ryangee"}},{"@type":"Answer","text":"SELECT schoolid as [SchoolID],\n\t\t\t\t\t\t(CASE \n\twhen schoolid = '1' then 'School Name 1' \n\twhen schoolid = '2' then 'School Name 2' \n\twhen schoolid = '3' then 'School Name 3' \n\twhen schoolid = '4' then 'School Name 4' \n\twhen schoolid = '5' then 'School Name 5' \n\twhen schoolid = '6' then 'School Name 6' \n\twhen schoolid = '7' then 'School Name 7' \n\twhen schoolid = '8' then 'School Name 8'\n\twhen schoolid = '9' then 'School Name 9' \n\twhen schoolid = '10' then 'School Name 10' \n\twhen schoolid = '11' then 'School Name 11' \n\twhen schoolid = '12' then 'School Name 12' \n\twhen schoolid = '13' then 'School Name 13' \n\twhen schoolid = '14' then 'School Name 14' \n\twhen schoolid = '15' then 'School Name 15' \n\twhen schoolid = '16' then 'School Name 16' \n\twhen schoolid = '17' then 'School Name 17' \n\t\t\t\t\t\tEND) AS [School_name],\n\n\tnumber as [School_number],\n\tdistrictid as [State_id],\n principalname as Principal,\n\tprincipalEmail as [Principal_email],\n\taddress as [School_address],\n\tcity as [School_city],\n\tstate as [School_state],\n\tzip as [School_zip],\n\tphone as [School_phone]\n\nFROM [ip address].database.dbo.table with(nolock)\nWHERE schoolID in ('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17')\nORDER BY schoolID\n<\/code><\/pre>\n