October 13, 2005 at 6:04 am
Hi. Recently I've found the following query:
USING Northwind
SELECT *
FROM Customers
ORDER BY
CASE Country
WHEN 'Canada' THEN char (1)
WHEN 'USA' THEN char (2)
WHEN 'Mexico' THEN char (3)
ELSE Country
END,
Region
I know what does this query do, but don't know exactly "how". Could someone explain it to me ?
Thank U in advance.
October 13, 2005 at 6:53 am
Well, when you sort letters like 'abc', you don't really sort by the letters, you use the configured ascii table to find which numbers that 'abc' correspond to, then you sort. So, 'abc' is from the computers view 979899.
CHAR(1) is the same as saying ASCII code #1 (which is some weird control char, but it's #1, so it'll always come first)
Enough explained?
/Kenneth
October 13, 2005 at 8:45 am
Thanks for Your explantion. I knew that it's assotiated with ASCII codes, but I didn't get the idea before writting my post
thx a lot
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply