Problem converting integer to uniqueidentifier

Hey people, I have Problem converting integer data type to uniqueidentifier in SQL Server 2005. I am using SSIS to copy data from one table to another. Source table has integer data type as the primary key and destination table has uniqueidentfier as primarykey. Is there any work around like mapping to another data type. Any alternate solutions. Please help
Who is Participating?
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
you  cannot transform a int into uniqueidentifier.

you can generate uniqueidentifier value with NEWID() or NEWSEQUENTIALID() function in the query, ie set NEWID() as default for the column in the destination table, and leave it out from the transformation.
As already mentioned by angelIII you cannot convert an int to a GUID. If you want to maintain a relationship to the source table your best workaround is to add another column to the destination.
if you have detail tables relared to your master table with the id key and you want to transfer that data then you should better use a cursor to tarnsfer teh data. Copy one row to the destination.. get the new id that is produced while you were inserting then copy the detail values by changing the id with new value...
Hope this helps
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

ajayanandvAuthor Commented:
I want to do bulk copy from the source table and since the destination type is unique identifier, i am not able to copy the data. I have tried using temporary tables to do the mapping. It just doesnt work. Are you aware of any techniques to make it work?
One other workaround. Just concat values together to form your own GUID. If you take an existing value from the table and say, drop off the last 6 chars - you could substitute those with a padded version of your integer value. Of course you do take the risk of  failoure if inserting a duplicate in your primary key.
Example value from table:
Here are some rows I inserted after this:

if your destination tables id field is an Identity field then you shouldnt care about the id fields... If not you may change it to be and Identity field...
In your package write a select stament including all columns except the id column as your source...
In the destination table insert these columns to the coressponding fields but do not try to assing any value to the id field of the destination table...
The package will transfer the package and produce the new id values ad unique identifier..
Here is some  code i messed around with to create my own id's. Caution! :-)
declare @varid as varchar(40);
declare @newid as uniqueidentifier;
select @newid = newid()
select @newid
select @varid = @newid
select @varid = substring(@varid,1,24)
declare @myIntVal as integer
select @myIntVal = 287654
declare @myVarInt as varchar(8)
declare @myVarBld as varchar(16)
select @myVarBld = '00000000' + cast(@myIntVal as varchar(8))
select @myVarBld
select substring(@myVarBld,len(@myVarBld)-7,8)
select @myVarInt = substring(@myVarBld,len(@myVarBld)-7,8)
select @myVarInt
declare @myVarFun as varchar(12);
select @myVarFun = 'HOGG';
select @myVarFun = @myVarFun + @myVarInt
select @myVarFun
select @varid = @varid + @myVarFun
select @varid

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.