![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have some code that I am using to import a flat file into a bunch of related tables. I am trying to make it so that new records are added to the related tables of a new value appears. However, my code thinks that every value is new and unique and creates a new entry for it. For example, one of the tables should have about 20 records in it. Instead, it comes out at 2428, the same number of lines in the text file. Here is my code: Dim InBound, InBoundID InBound = DTSSource("Col004") InBoundID = -1 Dim server Set server = CreateObject("ADODB.Connection") server.Open DTSGlobalVariables("ConnectionString").Value Dim ib Set ib = CreateObject("ADODB.Recordset") ib.Open "SELECT * FROM [TOFC].[dbo].[CITTAS_InBound_RailYard] WHERE InBoundRailYard = '" & InBound & "'", server If ib.RecordCount = -1 Then server.Execute "INSERT INTO [TOFC].[dbo].[CITTAS_InBound_RailYard] ([InBoundRailYard]) VALUES('" & InBound & "')" ib.Requery End If InBoundID = ib.Fields("InBoundRailYardID") ib.Close Set ib = Nothing Set server = Nothing DTSDestination("InBoundRailID") = InBoundID Main = DTSTransformStat_OK To my eye, it looks like if the value is already in the table CITTAS_InBound_RailYard, then its ID should be copied to the destination column. For some reason, the INSERT is called for every record. Any help is appreciated. Also, how do you reset the identity value to 1 again? Because of all of these extra records being inserted, the value is over 5000. I don't want to have to worry about an overflow in the future, so being able to reset this would be nice. Thanks in advance. -- Chris Lieb UPS CACH, Hodgekins, IL Tech Support Group - Systems/Apps |
#3
| |||
| |||
|
|
I have some code that I am using to import a flat file into a bunch of related tables. I am trying to make it so that new records are added to the related tables of a new value appears. However, my code thinks that every value is new and unique and creates a new entry for it. For example, one of the tables should have about 20 records in it. Instead, it comes out at 2428, the same number of lines in the text file. Here is my code: Dim InBound, InBoundID InBound = DTSSource("Col004") InBoundID = -1 Dim server Set server = CreateObject("ADODB.Connection") server.Open DTSGlobalVariables("ConnectionString").Value Dim ib Set ib = CreateObject("ADODB.Recordset") ib.Open "SELECT * FROM [TOFC].[dbo].[CITTAS_InBound_RailYard] WHERE InBoundRailYard = '" & InBound & "'", server If ib.RecordCount = -1 Then server.Execute "INSERT INTO [TOFC].[dbo].[CITTAS_InBound_RailYard] ([InBoundRailYard]) VALUES('" & InBound & "')" ib.Requery End If InBoundID = ib.Fields("InBoundRailYardID") ib.Close Set ib = Nothing Set server = Nothing DTSDestination("InBoundRailID") = InBoundID Main = DTSTransformStat_OK To my eye, it looks like if the value is already in the table CITTAS_InBound_RailYard, then its ID should be copied to the destination column. For some reason, the INSERT is called for every record. Any help is appreciated. Also, how do you reset the identity value to 1 again? Because of all of these extra records being inserted, the value is over 5000. I don't want to have to worry about an overflow in the future, so being able to reset this would be nice. Thanks in advance. -- Chris Lieb UPS CACH, Hodgekins, IL Tech Support Group - Systems/Apps |
#4
| |||
| |||
|
|
With flat files I always choose to BULK it into a staging table of the same structure. I then use TSQL to do my comparisons and queries. Can you not do that here? |
|
So you have a flat file that contains n tables worth of data? |
|
Because you have included the DTS NG I presume you are doing this is an Active Script task. |
#5
| |||
| |||
|
|
"Allan Mitchell" wrote: With flat files I always choose to BULK it into a staging table of the same structure. I then use TSQL to do my comparisons and queries. Can you not do that here? I don't have the permissions to use the Bulk Insert task. (It isn't easy being new. Bare bones permissions, always begging IT for more.) So you have a flat file that contains n tables worth of data? The flat file contains one table of data, I am just parsing it into multiple related tables. Because you have included the DTS NG I presume you are doing this is an Active Script task. Yes, I am. I have simmilar tasks for other fields, and they are all exhibiting this behavior. I don't know what is going on with my script. It would be easier to figure out the bug if there was a script debugger to use, but, alas, MS didn't provide us with one. The only possibility that I can come up with is that the quotes in the flat file are messing up the comparisons in my WHERE clauses. Outside of that, I don't know why my queries never return a row. Chris |
#6
| |||
| |||
|
|
OK So use the DataPump task to get the file in and then use TSQL to do the fancy stuff. Allan "Chris Lieb" <ChrisLieb (AT) discussions (DOT) microsoft.com> wrote in message news:ChrisLieb (AT) discussions (DOT) microsoft.com: "Allan Mitchell" wrote: With flat files I always choose to BULK it into a staging table of the same structure. I then use TSQL to do my comparisons and queries. Can you not do that here? I don't have the permissions to use the Bulk Insert task. (It isn't easy being new. Bare bones permissions, always begging IT for more.) So you have a flat file that contains n tables worth of data? The flat file contains one table of data, I am just parsing it into multiple related tables. Because you have included the DTS NG I presume you are doing this is an Active Script task. Yes, I am. I have simmilar tasks for other fields, and they are all exhibiting this behavior. I don't know what is going on with my script. It would be easier to figure out the bug if there was a script debugger to use, but, alas, MS didn't provide us with one. The only possibility that I can come up with is that the quotes in the flat file are messing up the comparisons in my WHERE clauses. Outside of that, I don't know why my queries never return a row. Chris |
#7
| |||
| |||
|
|
I am not very familliar with the structures of TSQL. How would you implement the record check that I use to insert new entries into other tables and retrieve the relevant ID? I can get the easy string manipulation stuff taken care of, but I don't know how to get the more complicated stuff done. Thanks Chris "Allan Mitchell" wrote: OK So use the DataPump task to get the file in and then use TSQL to do the fancy stuff. Allan "Chris Lieb" <ChrisLieb (AT) discussions (DOT) microsoft.com> wrote in message news:ChrisLieb (AT) discussions (DOT) microsoft.com: "Allan Mitchell" wrote: With flat files I always choose to BULK it into a staging table of the same structure. I then use TSQL to do my comparisons and queries. Can you not do that here? I don't have the permissions to use the Bulk Insert task. (It isn't easy being new. Bare bones permissions, always begging IT for more.) So you have a flat file that contains n tables worth of data? The flat file contains one table of data, I am just parsing it into multiple related tables. Because you have included the DTS NG I presume you are doing this is an Active Script task. Yes, I am. I have simmilar tasks for other fields, and they are all exhibiting this behavior. I don't know what is going on with my script. It would be easier to figure out the bug if there was a script debugger to use, but, alas, MS didn't provide us with one. The only possibility that I can come up with is that the quotes in the flat file are messing up the comparisons in my WHERE clauses. Outside of that, I don't know why my queries never return a row. Chris |
![]() |
| Thread Tools | |
| Display Modes | |
| |