Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 NewID() defualt length

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-02-16 : 07:56:40
Rajesh writes "The Result is generated by select newid() is the 36 long char, is there any way it will go more than 36 char . I mean to say that is there any setting for it change the defualt length of newid() ?"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2006-02-16 : 07:58:58
A uniqueidentifier is actually 16 bytes, it is only formatted to display as a 36 character string. You can format it to a different length like so:

SELECT cast(newid() as char(40))

...but I haven't got the slightest idea why you'd want to, and that will only add spaces to the end, it will not provide extra digits.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-02-16 : 07:58:59
Hi Rajesh, Welcome to SQL Team!

newid() is returning a GUID, and GUIDs are 36 characters long ...

What are you needing a different length object for?

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-16 : 08:06:29
What values do you want to have apart from what newid() returns?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-02-16 : 08:59:36
concat the newid() again ?
select left(convert(varchar(36), newid()) + convert(varchar(36), newid()), 40)


----------------------------------
'KH'

Time is always against us
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-02-16 : 09:59:53
How unique do you want it to be?

Kristen
Go to Top of Page
   

- Advertisement -