SSIS flow ADO.net source task with parameter

Deadly 提交于 2019-12-02 05:40:58

问题


I am using a ADO.NET source to bring data from an ODBC server to the my SQL. I used the import and export wizard to create my data flow task.

I need to append new records that have field GPMTADDT>(yesterday date) for example if today 20121002 the following query works perfectly:

SELECT  PARTICIP.* 
FROM PARTICIP
WHERE GPMTADDT > 20121001

I tried:

SELECT  PARTICIP.* 
FROM PARTICIP
WHERE GPMTADDT > Format(now(),"yyyymmdd")

But it will not work, the server treats "format" as a column. I tried creating a variable @date

SELECT  PARTICIP.* 
FROM PARTICIP
WHERE GPMTADDT > @date

again the server rejected the "@".

Also tried:
SELECT  PARTICIP.* 
FROM PARTICIP
WHERE GPMTADDT > (SELECT MAX PARTICIP.GPMTADDT FROM PARTICIP)

I am sure I am missing something simple, help will be greatly appreciated.

Thank you!


回答1:


Have you tried:

SELECT PARTICIP.*
FROM PARTICIP
WHERE GPMTADDT > DATEADD(dd, -1, GETDATE())



回答2:


You haven't mentioned what your data source actually is, but there appear to be several errors in the SQL syntax you've tried. e.g. the first query should have single quotes around the date, the last one should put the argument to MAX() in parentheses etc.

But to try to answer your basic question, ADO.NET sources do not support parameters, unlike OLE DB ones that do. Some possible solutions are:

  1. Don't use a parameter if you can generate the value in the source itself; this is what you are trying to do in your last example and what Jeff has suggested
  2. Use an SSIS expression to set the SqlCommand property of the connection object, together with an SSIS variable (as described here)
  3. As an alternative to #2, use a Script task to build the complete SELECT query, assign it to an SSIS variable, and then use that variable as the SqlCommand value

Personally I would say that option 1 is the easiest but of course not always possible, if the variable isn't accessible from within the source system. 2 and 3 are variations on the same solution, but I prefer 3 because I find writing a script easier than working with expressions.



来源:https://stackoverflow.com/questions/12697584/ssis-flow-ado-net-source-task-with-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!