Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7160537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:24:55+00:00 2026-05-28T13:24:55+00:00

In SSIS, How do I use the execute SQL task to insert a single

  • 0

In SSIS, How do I use the execute SQL task to insert a single row with no parameters and get the primary key back so I can set it to user variable? My insert query is simply:

INSERT INTO [AdWords.ImportData] (EndDate) VALUES (null)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:24:56+00:00Added an answer on May 28, 2026 at 1:24 pm

    Good question, took me a few tries to figure it out. Declare an SSIS variable of type Int32 (unless you need sizing for a bigint or numeric). I chose tablePk as mine.

    Option 1

    Execute SQL Task

    • General tab

    ResultSet: None

    SQL

    INSERT INTO dbo.ImportData (EndDate) VALUES (NULL);
    SELECT ? = SCOPE_IDENTITY()
    
    • Parameter Mapping tab

    Variable Name: User::tablePk

    Direction: Output

    Data Type: Long

    Parameter Name: 0

    Parameter Size: -1

    Option 2

    This was the original solution as I couldn’t grok how to get the placeholder ? in a normal query. It couldn’t as simple as what I had above, except it was.

    The only difference is the query used

    SQL

    DECLARE @sql nvarchar(500)
    , @paramDef nvarchar(500)
    
    SELECT
        @sql = N'INSERT INTO dbo.ImportData (EndDate) VALUES (NULL);
        SELECT @ident = SCOPE_IDENTITY();'
    ,   @paramDef = N'@ident int OUTPUT'
    EXECUTE sp_executesql @sql, @paramDef, @ident = ? OUTPUT
    

    Option 3

    If you’re using a data flow, I outline an approach on How to Add the Result Set from a T-SQL Statement to a Data Flow? In short, you need to add a column into the data flow prior to an OLE DB Command. Within the OLE DB Command, you will map that empty column into a OUTPUT parameter from your stored procedure and then as the stored procedure fires, it will replace the column with the value from the procedure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can we use SSIS with SQL Server (2005) Express as database?
I'm trying to use SSIS to extract XML representation of a query result set
How can I get SSIS to connect to an Oracle Hyperion Essbase cube to
We have recently migrated some 30 DTS packages in SQL Server 2000 to SSIS
I use Access 2007, SQL Server 2005 and 2008, and C#.net with VS20010. I
When would you use Integration Services and when would just use SQL/stored procedures? What
In SQL Server 2005, is it possible to schedule an SSIS package to run
I develop some application that has database wery generic so really can't use it
We are planning NOT to use MSDTC for transaction managment in SSIS and instead
I have an SSIS package that takes data from Tables in an SQL database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.