| Author |
Topic  |
|
|
ajthepoolman
Constraint Violating Yak Guru
USA
384 Posts |
Posted - 11/02/2006 : 10:19:25
|
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
11741 Posts |
|
|
khtan
In (Som, Ni, Yak)
Singapore
16746 Posts |
Posted - 11/02/2006 : 11:25:33
|
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
|
 |
|
|
spirit1
Cybernetic Yak Master
Slovenia
11741 Posts |
Posted - 11/02/2006 : 11:43:43
|
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 |
 |
|
|
ajthepoolman
Constraint Violating Yak Guru
USA
384 Posts |
Posted - 11/02/2006 : 11:51:26
|
My bad. I'm sorry for wasting your time. I found the bug, and it was in my code.
Aj
Hey, it compiles. |
 |
|
|
khtan
In (Som, Ni, Yak)
Singapore
16746 Posts |
Posted - 11/02/2006 : 11:52:00
|
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
|
 |
|
|
spirit1
Cybernetic Yak Master
Slovenia
11741 Posts |
Posted - 11/02/2006 : 12:01:03
|
> 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 |
 |
|
|
Kristen
Test
United Kingdom
22191 Posts |
Posted - 11/02/2006 : 12:10:00
|
"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 |
 |
|
|
spirit1
Cybernetic Yak Master
Slovenia
11741 Posts |
|
|
ajthepoolman
Constraint Violating Yak Guru
USA
384 Posts |
Posted - 11/02/2006 : 12:28:47
|
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. |
 |
|
| |
Topic  |
|