• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help With SQL Using GUIDs

 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, what is the matter with this:

SELECT NEWID()
GO
/******This will return a new random unique identifier, e.g., ******/
/******E75B92A3-3299-4407-A913-C5CA196B3CAB ******/

/******assign uniqueidentifier in a variable ******/

DECLARE @MessageID uniqueidentifier

SET @MessageID = NEWID()


/****** Inserting data in map_Missing_ADT table. ******/

INSERT INTO [DEPTH].[correction].[map_Missing_ADT]
(MapID, TypeID, MessageID, Value, Description)
VALUES
('5806D9F7-D836-456B-92E1-20AFC9F9358A', 'IC', '(NEWID()', 'D14', 'XYZ COMPANY')

I think it is expecting the NewID() to come first but it doesn't. It also doesn't need quotes but SQLServer errored out until I did that. Any help appreciated.


Thanks,
 
Imre Parusef
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Michele

SQL Server is OK, You don't need quotes with NEWID(), but You mispelled this: (NEWID()
Is it a copied statement or mispelled when wrote this forum post?

Jimmy
 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am now receiving this error:

Conversion failed when converting from a character string to uniqueidentifier.

SELECT NEWID()
GO
/******This will return a new random unique identifier, e.g., ******/
/******E75B92A3-3299-4407-A913-C5CA196B3CAB ******/

/******assign uniqueidentifier in a variable ******/

DECLARE @MessageID uniqueidentifier

SET @MessageID = NEWID()

/****** Inserting data in map_Missing_ADT table. ******/

INSERT INTO [DEPTH].[correction].[map_Missing_ADT]
(MapID, TypeID, MessageID, Value, Description)
VALUES
('5806D9F7-D836-456B-92E1-20AFC9F9358A', 'IC', '(NEWID()', 'D14', 'xyzcompany')

Msg 8169, Level 16, State 2, Line 12
Conversion failed when converting from a character string to uniqueidentifier.
 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
figured it out.

Thanks,
Michele
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic