How to pass SSIS variables in ODBC SQLCommand expression?

前端 未结 1 1376
独厮守ぢ
独厮守ぢ 2020-12-12 03:21

I\'m trying to load incremental data from ODBC server to SQL server using common table expression. When running the query in the Dbeabver application, is executed correctly:

相关标签:
1条回答
  • 2020-12-12 03:43
    • With OLE DB

    Try this code, it works for me with my own tables with SQL Server :

    SELECT userid,sum(goldbalance) AS SUMGOLD
    FROM deltadna.events_live
    WHERE eventTimestamp >= DATEADD(DAY, -100,CONVERT(DATE,?))
    GROUP BY userid
    ORDER BY SUMGOLD desc
    

    You have to click on Parameters in the OLEDB Source Editor to configure what you need. Use the '?' to represent a variable in your query.

    If you query if too complicated, stored it in a stored procedure and call it like this:

    EXEC shema.storedProcedureName ?
    

    And map the '?' to your variable @user::DateString

    • With ODBC

    The expressions are outside the data flow in Data Flow Properties. Select the expression property and add your dynamic query.

    And your expression will be

    "SELECT userid,sum(goldbalance) AS SumGold
    FROM deltadna.events_live
    where eventTimestamp>=DATE "+@[User::datestring]+" +INTERVAL '-100 day'
    group by userid
    order by SumGold desc"
    
    0 讨论(0)
提交回复
热议问题