How can I add a GUID column in SSIS from a Flat File source before importing to a SQL Table?

StackOverflow https://stackoverflow.com/questions/17453170

  •  02-06-2022
  •  | 
  •  

Domanda

I'm importing flat files through SSIS which then exports them into a SQL table. I need to add an additional column containing a GUID somewhere in the middle so that it can also be exported to the table.

I've made sure there's an additional column ready in the SQL Table for the GUID to be passed into but I'm unsure of how to create the GUID in the package, any ideas?

Thanks

È stato utile?

Soluzione

You can do this via a Script Component Transformation.

In your data flow task, between source and destination, add the script component. Under 'Inputs and Outputs' add an output column, name it as you like and in Data Type Properties give it DataType of unique identifier [DT_GUID]

Use this script (Make sure ScriptLanguage is VB.net):

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper

<microsoft.sqlserver.dts.pipeline.ssisscriptcomponententrypointattribute> _
<clscompliant(false)> _
Public Class ScriptMain
    Inherits UserComponent

    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
        ' Create a Globally Unique Identifier with SSIS
        Row.Guid = System.Guid.NewGuid()
    End Sub
End Class

Altri suggerimenti

below link should help you .

  1. Add a derived transform
  2. add a new column
  3. get dt_guid

here the link with more details http://microsoft-ssis.blogspot.com/2011/02/create-guid-column-in-ssis.html

best of luck

You can do this with a Script Component, or a Custom Data Flow Component.

Use NewGuid to make a new guid for each row.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top