Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL query not working as expected

I am using the standard ASP.NET Membership table structure in SQL Server and was doing a bit of manually querying in Management studio and ran this query

SELECT *
FROM [aspnet_Users]
WHERE UserId = '2ac5dd56-2630-406a-9fb8-d4445bc781da&cID=49'

Notice the &cID=49 at the end - I copied this from a querystring and forgot to remove that part.

However, to my surprise it returned the data correctly (there is a user with the ID 2ac5dd56-2630-406a-9fb8-d4445bc781da) - any idea why this works? To my mind it should not match or probably more likely throw an error as it shouldn't be able to convert to a Guid?

like image 476
Kevin Main Avatar asked May 02 '12 08:05

Kevin Main


1 Answers

The uniqueidentifier type is considered a character type for the purposes of conversion from a character expression, and therefore is subject to the truncation rules for converting to a character type. That is, when character expressions are converted to a character data type of a different size, values that are too long for the new data type are truncated.

Because the uniqueidentifier type is limited to 36 characters, the characters that exceed that length are truncated.

Note that above is quoted from MSDN

like image 112
Tim Schmelter Avatar answered Oct 28 '22 17:10

Tim Schmelter