{"id":32,"date":"2007-09-13T21:52:49","date_gmt":"2007-09-14T02:52:49","guid":{"rendered":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/32_ssis-issue-with-ole-db-source-component-that-is-based-on-parametrized-sql-query"},"modified":"2008-03-17T20:59:31","modified_gmt":"2008-03-18T01:59:31","slug":"ssis-issue-with-ole-db-source-component-that-is-based-on-parametrized-sql-query","status":"publish","type":"post","link":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/32_ssis-issue-with-ole-db-source-component-that-is-based-on-parametrized-sql-query","title":{"rendered":"SSIS: Issue with OLE DB Source component that is based on parametrized SQL Query"},"content":{"rendered":"<p>While writing SSIS package to load one of my\u00a0data warehouse tables, I\u00a0encountered\u00a0SSIS problem that took me some time to figure out.\u00a0I noticed that in the dataflow task one of the OLE DB source components was not returning any data even I know that records were there. So I did some investigation and found what was causing this issue.<\/p>\n<p>I found that when following conditions are met, OLE DB Source component will not return any data:<\/p>\n<ul>\n<li>&#8220;OLE DB Source&#8221; component is based on the SQL Query<\/li>\n<li>SQL Query\u00a0contains parameters<\/li>\n<li>SQL Query\u00a0contains line that starts with comments symbol &#8220;&#8211;&#8221;\u00a0<\/li>\n<\/ul>\n<p>\u00a0Example, this query (database &#8220;Adventure Works DW&#8221;) works:<\/p>\n<blockquote><p>SELECT CurrencyKey<br \/>\n\u00a0 FROM dbo.DimCurrency<br \/>\nWHERE CurrencyKey BETWEEN ? AND ?<\/p><\/blockquote>\n<p>But this query always returns empty result set:<\/p>\n<blockquote><p>SELECT CurrencyKey<br \/>\nFROM dbo.DimCurrency<br \/>\n&#8212; my comments<br \/>\nWHERE CurrencyKey BETWEEN ? AND ?<\/p><\/blockquote>\n<p><!--more--><\/p>\n<p>Here are quick steps to reproduce this issue:<\/p>\n<ul>\n<li>In Adventure Works DW database create new table based on the script<\/li>\n<\/ul>\n<blockquote>\n<blockquote><p>IF OBJECT_ID(&#8216;dbo.tmpKey&#8217;) IS NOT NULL DROP TABLE tmpKey;<br \/>\nCREATE TABLE tmpKey (CurrencyKey int NOT NULL);<\/p><\/blockquote>\n<\/blockquote>\n<blockquote><p>This will be our destination table and you can delete this table after this test.<\/p><\/blockquote>\n<ul>\n<li>Start BIDS and create new SSIS project and then SSIS package.<\/li>\n<li>Add OLE DB connection to Adventure Works DW database. Name it DB for simplicity.<\/li>\n<li>Add &#8220;Execute SQL&#8221; task to control flow. Change connection to DB and SQL Statement to:<\/li>\n<\/ul>\n<blockquote>\n<blockquote><p>IF OBJECT_ID(&#8216;dbo.tmpKey&#8217;) IS NOT NULL DROP TABLE tmpKey;<br \/>\nCREATE TABLE tmpKey (CurrencyKey int NOT NULL);<\/p><\/blockquote>\n<\/blockquote>\n<blockquote><p>This way we will be able to run package multiple times.<\/p><\/blockquote>\n<ul>\n<li>Add two variables to package:<br \/>\nName: MinID Type: Int32 value 1<br \/>\nName: MaxID Type: Int32 value 2<\/li>\n<li>Add data flow task and connect it to go after &#8220;Execute SQL&#8221; task.<\/li>\n<li>Double click on data flow task to go into data flow area.<\/li>\n<li>Add &#8220;OLE DB source&#8221; and &#8220;OLE DB destination&#8221; components. Make connection from &#8220;OLE DB Source&#8221; to &#8220;OLE DB Destination&#8221;<\/li>\n<li>Change &#8220;OLE DB source&#8221; properties:<br \/>\n\u00a0 Connection: DB<br \/>\n\u00a0 Data Access Mode: SQL Command<br \/>\n\u00a0 SQL Command text:<br \/>\n\u00a0 SELECT CurrencyKey<br \/>\n\u00a0\u00a0\u00a0 FROM dbo.DimCurrency<br \/>\n\u00a0 WHERE CurrencyKey BETWEEN ? and ?<\/li>\n<li>For &#8220;OLE DB Source&#8221; component click on &#8220;Parameters&#8221; button and map parameters:<br \/>\n\u00a0 Parameter0\u00a0 User::MinID<br \/>\n\u00a0 Parameter1\u00a0 User::MaxID<\/li>\n<li>Change &#8220;OLE DB Destination&#8221; properties<br \/>\n\u00a0 Connection: DB<br \/>\n\u00a0 Data access mode: &#8220;Table or view &#8211; fast load&#8221;<br \/>\n\u00a0 Name of the table or the view: &#8220;dbo.tmpKey&#8221;<br \/>\n\u00a0 Click on Mappings and map &#8220;CurrencyKey&#8221; to &#8220;CurrencyKey&#8221;<\/li>\n<li>Add data viewer to see records moving between &#8220;OLE DB Source&#8221; and &#8220;OLE DB Destination&#8221;<\/li>\n<li>Save and execute package. You will see 2 rows moved between source and destination. That is correct behaviour.<\/li>\n<li>Now change &#8220;OLE DB Source&#8221; SQL command text to:<br \/>\nSELECT CurrencyKey<br \/>\n\u00a0 FROM dbo.DimCurrency<br \/>\n&#8212; my comment line<br \/>\nWHERE CurrencyKey BETWEEN ? and ?<\/li>\n<li>Save and execute package. No data will be moved.\u00a0That I believe is a bug.<\/li>\n<\/ul>\n<p>I submitted this issue to Microsoft connect website:<\/p>\n<p><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/connect.microsoft.com\/SQLServer\/feedback\/ViewFeedback.aspx?FeedbackID=298046\">https:\/\/connect.microsoft.com\/SQLServer\/feedback\/ViewFeedback.aspx?FeedbackID=298046<\/a><\/p>\n<p>Of course, workaround for this problem is to remove line that starts with comments.<\/p>\n<p><strong>Mar 14th, 2008 update. Microsoft reply:<\/strong><\/p>\n<p><strong>The problem that you have described is an issue with the SQL Server Native Client provider. This problem occurs with a parameterized SQL query using in SSIS components such as the OLE DB Source, when the query contains a comment line that begins with the comment characters &#8220;&#8211;&#8220;. The OLE DB Source does not parse the SQL statement (because it must support the varying SQL syntax of various data sources) and cannot catch the problem. The only solution is to omit comments from parameterized SQL statements used in the OLE DB Source.<br \/>\n<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>While writing SSIS package to load one of my\u00a0data warehouse tables, I\u00a0encountered\u00a0SSIS problem that took me some time to figure out.\u00a0I noticed that in the dataflow task one of the OLE DB source components was not returning any data even I know that records were there. So I did some investigation and found what was [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,5],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/wp-json\/wp\/v2\/posts\/32"}],"collection":[{"href":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/wp-json\/wp\/v2\/comments?post=32"}],"version-history":[{"count":0,"href":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/wp-json\/wp\/v2\/posts\/32\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/wp-json\/wp\/v2\/media?parent=32"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/wp-json\/wp\/v2\/categories?post=32"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/wp-json\/wp\/v2\/tags?post=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}