locked
Getting values from database using script task RRS feed

  • Question

  • I want to get some values from the database using script task. 

    In table , i have

    ID      Value

    1          A

    2          B

    I want to get the value of ID 1 and 2 using script task.  Because i want to store them in SSIS package.

    How to do it.  Thanks.


    NSG12
    Monday, December 19, 2011 6:05 PM

Answers

  • If I understood you correctly you don't really need script task - what you need is "Execute SQL Task".

    In SSIS you will declare 2 variables - VarA and VarB

    Then you can create SQL Task with VarA as a parameter and in the task specify this for SQL query:

     

     

    SELECT ? = dbo.MyTable.Value
    
    FROM dbo.MyTable
    
    WHERE ID=1
    

    Then you can create another Execute SQL Task to set VarB (you probably can set 2 variables in the same task but I used simpler version as example)

     

    • Proposed as answer by Todd McDermid Tuesday, December 20, 2011 4:19 PM
    • Marked as answer by Eileen Zhao Friday, December 23, 2011 7:03 AM
    Monday, December 19, 2011 9:37 PM

All replies

  • Hi, if you want to use script task you can do it in c# or vb.net.

    For c# check the following code examples on how to read data from database:

    http://msdn.microsoft.com/en-us/library/dw70f090%28v=VS.90%29.aspx

    David.

    Monday, December 19, 2011 6:11 PM
  • The above link reads and stores in a a datareader.  But , how do i store it to a variable.
    NSG12
    Monday, December 19, 2011 8:45 PM
  • If I understood you correctly you don't really need script task - what you need is "Execute SQL Task".

    In SSIS you will declare 2 variables - VarA and VarB

    Then you can create SQL Task with VarA as a parameter and in the task specify this for SQL query:

     

     

    SELECT ? = dbo.MyTable.Value
    
    FROM dbo.MyTable
    
    WHERE ID=1
    

    Then you can create another Execute SQL Task to set VarB (you probably can set 2 variables in the same task but I used simpler version as example)

     

    • Proposed as answer by Todd McDermid Tuesday, December 20, 2011 4:19 PM
    • Marked as answer by Eileen Zhao Friday, December 23, 2011 7:03 AM
    Monday, December 19, 2011 9:37 PM
  • Thanks.
    NSG12
    Monday, December 19, 2011 10:22 PM