johnecollins
asked on
How do I create valid uniqueidentifier values when importing data from Excel into an MSSQL table.
How do I create valid uniqueidentifier values when importing data from Excel into an MSSQL table. The default value for the field in table design is (newid()).
The DTS wizard generates this script, which I have tried to “improve” with marked line.
'************************* ********** ********** ********** ********** *****
' Visual Basic Transformation Script
' Copy each source column to the
' destination column
'************************* ********** ********** ********** ********** *******
Function Main()
DTSDestination("ID")=newid () ‘ Improved Line
DTSDestination("Season") = DTSSource("Season")
DTSDestination("League") = DTSSource("League")
DTSDestination("Junior") = DTSSource("Junior")
DTSDestination("Division") = DTSSource("Division")
DTSDestination("Team_1") = DTSSource("Team_1")
DTSDestination("Team_2") = DTSSource("Team_2")
DTSDestination("Team_3") = DTSSource("Team_3")
DTSDestination("Team_4") = DTSSource("Team_4")
DTSDestination("Team_5") = DTSSource("Team_5")
DTSDestination("Team_6") = DTSSource("Team_6")
DTSDestination("Division_S core") = DTSSource("Div Score")
Main = DTSTransformStat_OK
End Function
Would I be better off writing code in the table insert trigger? If so can anybody help with the necessary code and how do I enter it.
The DTS wizard generates this script, which I have tried to “improve” with marked line.
'*************************
' Visual Basic Transformation Script
' Copy each source column to the
' destination column
'*************************
Function Main()
DTSDestination("ID")=newid
DTSDestination("Season") = DTSSource("Season")
DTSDestination("League") = DTSSource("League")
DTSDestination("Junior") = DTSSource("Junior")
DTSDestination("Division")
DTSDestination("Team_1") = DTSSource("Team_1")
DTSDestination("Team_2") = DTSSource("Team_2")
DTSDestination("Team_3") = DTSSource("Team_3")
DTSDestination("Team_4") = DTSSource("Team_4")
DTSDestination("Team_5") = DTSSource("Team_5")
DTSDestination("Team_6") = DTSSource("Team_6")
DTSDestination("Division_S
Main = DTSTransformStat_OK
End Function
Would I be better off writing code in the table insert trigger? If so can anybody help with the necessary code and how do I enter it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could specify the column type as Identity on the SQL Server side, and it would automatically generate the ID's for you.
Hi johnecollins,
Thanks for the points and closing the question.
But may I ask why the B-grade?
Did you need more information?
D'Mzz!
RoverM
Thanks for the points and closing the question.
But may I ask why the B-grade?
Did you need more information?
D'Mzz!
RoverM
ASKER
RoverM,
This is the fourth time I have tried to respond to you, I have discovered why I get a problem now - I keep using the tab key to format my response and instead tab right out of this screen back to the question - losing my edits.
Attempt number 1 was to give you a the error that I got when I tried to compile your answer. (I have since lost that!).
Earlier today I tried attempt number 2 and did the accept your answer at the same time and lost my edits
Attempt no 3 I tried to format my response with tabs and went back to the question lost my edits!
Now here I am your response was timely and it looked just the job to my untutored brain. However it wouldn't compile and although I tried all manner of variations Imports System.Guid and so on, I could not get it to compile.
I actually ending up writing a sql script in Excel using newid() for the ID field.
Your answer does still look of great interest as I will make use of it later.
So thank you for your effort, I am grateful but it didn't have all of what I needed but it was my fault I hadn't let you know that. So maybe I was a bit harsh
John
TheLearnedOne,
Thanks for your suggestion, but that is how I had defined the in sql
Thank you
John
This is the fourth time I have tried to respond to you, I have discovered why I get a problem now - I keep using the tab key to format my response and instead tab right out of this screen back to the question - losing my edits.
Attempt number 1 was to give you a the error that I got when I tried to compile your answer. (I have since lost that!).
Earlier today I tried attempt number 2 and did the accept your answer at the same time and lost my edits
Attempt no 3 I tried to format my response with tabs and went back to the question lost my edits!
Now here I am your response was timely and it looked just the job to my untutored brain. However it wouldn't compile and although I tried all manner of variations Imports System.Guid and so on, I could not get it to compile.
I actually ending up writing a sql script in Excel using newid() for the ID field.
Your answer does still look of great interest as I will make use of it later.
So thank you for your effort, I am grateful but it didn't have all of what I needed but it was my fault I hadn't let you know that. So maybe I was a bit harsh
John
TheLearnedOne,
Thanks for your suggestion, but that is how I had defined the in sql
Thank you
John
Too bad that it didn't work out for you. Thanks for responding tho!
You should NOT have to import any namespace.
GUID is a member of SYSTEM. So if you use the full writing (System.Guid....) it should work.
D'Mzz!
RoverM
You should NOT have to import any namespace.
GUID is a member of SYSTEM. So if you use the full writing (System.Guid....) it should work.
D'Mzz!
RoverM