From: Mukul Jain on
Hi,

We have three fields in a table with primary and foreign key relationship.
Field1 data type 'nvarchar'
Field2 data type 'Int' and Field3 data type is 'Int'
Now I am trying to move a field from different table where the data type for
that field is UniqueIdentifier.
I am not able to do this. Please help how can i move the UniqueIdentifier
data type field into 'Int'.

Thanks in Advanced.
Mukul

From: John Bell on
On Tue, 25 May 2010 06:48:01 -0700, Mukul Jain
<MukulJain(a)discussions.microsoft.com> wrote:

>Hi,
>
>We have three fields in a table with primary and foreign key relationship.
>Field1 data type 'nvarchar'
>Field2 data type 'Int' and Field3 data type is 'Int'
>Now I am trying to move a field from different table where the data type for
>that field is UniqueIdentifier.
>I am not able to do this. Please help how can i move the UniqueIdentifier
>data type field into 'Int'.
>
>Thanks in Advanced.
>Mukul


Hi Mukul

Why would you want to convert a uniqueidentifier which is a GUID e.g.
FFFFFFFF-31BB-4D83-8B3C-3878EB6E0D22 to an integer?

John
From: Gert-Jan Strik on
Mukul Jain wrote:
>
> Hi,
>
> We have three fields in a table with primary and foreign key relationship.
> Field1 data type 'nvarchar'
> Field2 data type 'Int' and Field3 data type is 'Int'
> Now I am trying to move a field from different table where the data type for
> that field is UniqueIdentifier.
> I am not able to do this. Please help how can i move the UniqueIdentifier
> data type field into 'Int'.
>
> Thanks in Advanced.
> Mukul

Mukul,

Internally, a uniqueidentifier requires 16 bytes of storage. An int only
4. You cannot convert a uniqueidentifier to an int (without significant
loss of precision).

If this is a one time only conversion, you could test if
CHECKSUM(my_nvarchar) results in a unique int value for each
uniqueidentifier and go with that. Otherwise, you will have to map each
each individual uniqueidentifier ("map" them).

--
Gert-Jan