SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Development Tools
 ASP.NET
 GUIDs coming back as UPPERCASE
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ajthepoolman
Constraint Violating Yak Guru

USA
384 Posts

Posted - 11/02/2006 :  10:19:25  Show Profile  Reply with Quote
Hello all! I am running into a weird problem. My application is doing a quick insert into my CHILD table so I can get the GUID that it creates. When I look at the table values, the GUID letters are lowercase. But when I check the .Parameters("@CHILD_GUID_out").Value, the letters are all UPPERCASE.

Why is this happening? I know that I could put a .ToLower on it and force them to lowercase, but don't I then run the risk of screwing up a GUID that came back with mixed case?

Any suggestions would be appreciated!

Aj

Hey, it compiles.

spirit1
Cybernetic Yak Master

Slovenia
11749 Posts

Posted - 11/02/2006 :  11:04:35  Show Profile  Visit spirit1's Homepage  Reply with Quote
aren't GUID's case insensitive anyway?



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17431 Posts

Posted - 11/02/2006 :  11:25:33  Show Profile  Reply with Quote
from BOL
quote:
The uniqueidentifier data type stores 16-byte binary values that operate as globally unique identifiers (GUIDs). A GUID is a unique binary number

GUID is basically 16-byte binary values. There isn't such things as upper case or lower case in binary values (or integer)


KH

Go to Top of Page

spirit1
Cybernetic Yak Master

Slovenia
11749 Posts

Posted - 11/02/2006 :  11:43:43  Show Profile  Visit spirit1's Homepage  Reply with Quote
sql server always returns GUID's in uppercase.
It of course isn't case insensitive but looks like that sql server first converts the guid to uppercase before putting it into the db.

create table test (id uniqueidentifier)
go
insert into test(id)
select 'c9D38635-C103-483D-A6B8-B81603530176' union all
select 'C9D38635-C103-483D-A6B8-B81603530176'

select id, cast(id as varbinary)
from test
go
drop table test




Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

ajthepoolman
Constraint Violating Yak Guru

USA
384 Posts

Posted - 11/02/2006 :  11:51:26  Show Profile  Reply with Quote
My bad. I'm sorry for wasting your time. I found the bug, and it was in my code.

Aj

Hey, it compiles.
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17431 Posts

Posted - 11/02/2006 :  11:52:00  Show Profile  Reply with Quote
i think this is just how SQL Server present the GUID. It is more of a presentation issue.

The GUID is a 16 byte binary values. When you select newid() SQL server generates a 16 byes unique binary value. And It is presented in hexadecimal (in upper case) with 4 dash in between. So the length of the len(newid()) is 36 (16 x 2 + 4).


KH

Go to Top of Page

spirit1
Cybernetic Yak Master

Slovenia
11749 Posts

Posted - 11/02/2006 :  12:01:03  Show Profile  Visit spirit1's Homepage  Reply with Quote
> i think this is just how SQL Server present the GUID. It is more of a presentation issue.

I don't think so.
if that were so then cast(id as varbinary) in my example would be different also.
so it goes:
1. get the guid
2. upper case it
3. store that in binary.




Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

Kristen
Test

United Kingdom
22403 Posts

Posted - 11/02/2006 :  12:10:00  Show Profile  Reply with Quote
"looks like that sql server first converts the guid to uppercase before putting it into the db"

I reckon its converting them to some Numeric Representation ... so no chance to preserve case as well!

Kristen
Go to Top of Page

spirit1
Cybernetic Yak Master

Slovenia
11749 Posts

Posted - 11/02/2006 :  12:16:44  Show Profile  Visit spirit1's Homepage  Reply with Quote
well chars are all numbers anyway



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

ajthepoolman
Constraint Violating Yak Guru

USA
384 Posts

Posted - 11/02/2006 :  12:28:47  Show Profile  Reply with Quote
Thanks everyone. This is my first time working with GUIDs. I came from the world of integer based primary keys, so I am struggling with some of the adjustments that come with working with guids. Doesn't help when I botch my select statements with inner joins when it should of been left joins!

Thanks again!

Aj

Hey, it compiles.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000