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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Steve HoggITCommented:
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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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?
Steve HoggITCommented:
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..
Steve HoggITCommented:
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

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.