How to convert UNIQUEIDENTIFIER to INT?

Asked

Viewed 47 times

0

So quiet people? I’m beginner with SQL SERVER and I’m in a situation where I don’t know how to proceed anymore. I have 2 banks on a server here at the company, and I need to replicate some data that is in one table to another. However I need to treat a UNIQUEIDENTIFIER for INT but I have no idea how to do this, apparently it is something easy but I could not find anything about it. Follow the query I made below:

INSERT INTO [ITControl].[dbo].[Server] (Name, IP, Description, IdPlant, IdServerType)
SELECT [IPServidor], [NomeServidor], [DescricaoServidor], [IdAmbiente], [IdTipoServidor]
FROM [BAC].[dbo].[Servidor]
WHERE [IdAmbiente] = 'FDE2C706-A103-441A-AB43-1D62517B392E' AND [IdTipoServidor] = '96F5D942-3283-4542-8D78-A4A3D8A3D208'

The problem itself is that in my bank BAC, on the table Servidor my data from the fields [IdAmbiente] and [IdTipoServidor] are of the type UNIQUEIDENTIFIER. Already in my other bank called ITControl on the table Server the fields that would receive this data are of the type INT, my doubt is how I make to pass a INT in place of UNIQUEIDENTIFIER? I wanted to pass the value 7 to the [IdAmbiente] and value 1 for the [IdTipoServidor]

  • 1

    If you repair the ID is a GUID in this case, so it will not work to pass the GUID value to an INT. To solve I advise you to create a table (ID_NOVO, ID_ANTIGO). So you can connect the old id to an id of type INT

  • This is called incompatible data, it’s not like I see it as doing this, all they said is gambiarra, why not pass the same type to the other bank? (wrong modeling, almost sure, bank gambiarra, almost other certainty)

  • 2

    People here from the company helped me, I’m still intern kkk by what it seems I didn’t know very well what I was doing. I’ll post the resolution

1 answer

0


Good gentlemen, with the help of my teammates I managed to solve. In my line where I did the SELECT (line 2) I just changed the [IdAmbiente] and the [IdTipoServidor] for the values I needed (in case INT 7 and 1) and ready! entered the values I wanted from the bank BAC in the ITControl replacing the UNIQUEIDENTIFIER for INT. Follow the result below as was the new query:

INSERT INTO [ITControl].[dbo].[Server] (Name, IP, Description, IdPlant, IdServerType)
SELECT [IPServidor], [NomeServidor], [DescricaoServidor], 7, 1
FROM [BAC].[dbo].[Servidor]
WHERE [IdAmbiente] = 'FDE2C706-A103-441A-AB43-1D62517B392E' AND [IdTipoServidor] = '96F5D942-3283-4542-8D78-A4A3D8A3D208'

I hope I helped ;D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.