File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Help With SQL Using GUIDs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Help With SQL Using GUIDs" Watch "Help With SQL Using GUIDs" New topic
Author

Help With SQL Using GUIDs

Michele Smith
Ranch Hand

Joined: Oct 27, 2010
Posts: 412
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

Joined: May 09, 2012
Posts: 3
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

Joined: Oct 27, 2010
Posts: 412
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

Joined: Oct 27, 2010
Posts: 412
figured it out.

Thanks,
Michele
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help With SQL Using GUIDs