0

I am inserting data from csv flat file to sql table using ssis package. I added a new column to the destination table called GUID. I need to insert the same guid for all rows every time the package runs. The problem is that it generates new guid for every row.

crthompson
  • 15,653
  • 6
  • 58
  • 80
user2536008
  • 215
  • 1
  • 5
  • 15
  • 1
    What's the destination table's definition? most important to include is the GUID's column name and type, including the default definition for the column. – Jaaz Cole Apr 16 '15 at 22:06
  • I added a column name GUID with datatype uniqueidentifier. If iset the default value to newid(), each row will get a different guid. I am trying to have the same guid for all rows when the package runs. When the package runs at different time, it should generate a new guid for all rows. Is it possible? – user2536008 Apr 16 '15 at 22:14
  • I would generate the GUID once in the SSIS package and append to each of the rows. Then you will be inserting the same value each time. – DeanOC Apr 16 '15 at 22:17
  • It's possible, yes. You need an extra step in the package to generate the RunID (execute SQL and get the result into a variable), then, when you're inserting data (however you're doing it), pass the RunID variable into the query as a parameter that is selected as the value for the GUID column. – Jaaz Cole Apr 16 '15 at 22:19

1 Answers1

0

You need an extra step in the package to generate the RunID (execute SQL and get the result into a variable), then, when you're inserting data (however you're doing it), pass the RunID variable into the query as a parameter that is selected as the value for the GUID column.

Jaaz Cole
  • 3,119
  • 1
  • 15
  • 20
  • How do I generate it in SSIS? I tried using derived column but not sure how to generate the same guid for all rows – user2536008 Apr 16 '15 at 22:38
  • Im having the same problem. Im loading a data warehouse where the natural key is a GUID and when a record cant be found I need to default it to the generic (-1) GUID. I cannot for the life of me find a way to do this. The only option I have is to insert it into the temp table where the column is a varchar and then convert before inserting into the table using TSQL. – BilliD Mar 09 '17 at 16:30