We help IT Professionals succeed at work.

GUID copied from one table to another

803 Views
Last Modified: 2014-07-15
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')
Comment
Watch Question

Raja Jegan RSQL Server DBA & Architect, EE Solution Guide
CERTIFIED EXPERT
Awarded 2009
Distinguished Expert 2019

Commented:
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

Author

Commented:
The thing is I have these set up as a cursor.
Raja Jegan RSQL Server DBA & Architect, EE Solution Guide
CERTIFIED EXPERT
Awarded 2009
Distinguished Expert 2019

Commented:
Hi LuckyLucks,

I didn't get what you meant..
Can you kindly clarify..
Database Administrator / Software Engineer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.