Avatar of LuckyLucks
 asked on

GUID copied from one table to another

Hello EEE
I have a GUID value that is retreived from a table1 that I am trying to insert into table2. Both the source and destination tables have the datatype uniqueidentifier. However, on an insert to table2,  this column is being set to null. Can we copy guid columns from one table to another? Or is the issue something else.

declare @myGUIDsrc uniqueidentifier

select  @myGUIDsrc = column1  from table1  <---- only one row and GUID value is returned

insert into table2 (column1, column2) values (@myGUIDsrc , 'TEST')
Microsoft SQL ServerMicrosoft SQL Server 2008SQL

Avatar of undefined
Last Comment
Tomas Helgi Johannsson

8/22/2022 - Mon
Raja Jegan R

Yes, we can insert GUID values from one table to another..
But you need to use another format to insert the records and use WHERE clauses as required..
insert into table2 (column1, column2) 
SELECT column1, 'TEST'
from table1

Open in new window


The thing is I have these set up as a cursor.
Raja Jegan R

Hi LuckyLucks,

I didn't get what you meant..
Can you kindly clarify..
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Tomas Helgi Johannsson

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question