sylvar: (Hmmm. (Giles))
sylvar ([personal profile] sylvar) wrote2005-02-14 06:47 pm

Transact-SQL

So I'm learning Transact-SQL for Sybase, particularly as it applies to our library automation system, and someone asks "How can I get a list of all books with all-capital titles?"

Offhand I thought this would work:

select bib.bib#, title.processed
from bib, title
where bib.bib# = title.bib#
and title.processed = upper(title.processed)


But it turns out that our SQL server was installed as case-insensitive for developers' convenience, so the answer is that you can't do it this way. But you can if you do a loop through all lower-case letters of the alphabet (preferably from a table of letter frequency), breaking if you find any lower-case letters (searching by ASCII code), and printing the book's title if none are found. (This also includes books like "1, 2, 3", but that's a minor problem.

You shouldn't do this because it's time-consuming to check the entire title of every single book. It wouldn't be necessary to do this if the server were case-sensitive, but oh well.

The better answer is to export a list of titles to a text file and pipe it through a script that does what case-insensitive installations of SQL can't do.

Ugh. Perl Boy here was trying 'eq', '==', and all sorts of other operators until this finally dawned on him...

[identity profile] cbustapeck.livejournal.com 2005-02-15 12:47 am (UTC)(link)
Um, /me is a little scared by the thought of someone doing that on his opac. How big is your database?

[identity profile] sylvar.livejournal.com 2005-02-15 03:30 am (UTC)(link)
Well, it doesn't affect the opac that much, since the opac searches are run against indexes, not the live database.
ximinez: (Default)

[personal profile] ximinez 2005-02-15 03:28 pm (UTC)(link)
So I'm learning Transact-SQL for Sybase, particularly as it applies to our library automation system, and someone asks "How can I get a list of all books with all-capital titles?"

Proper answer: you can't because some bozo installed the server case-insensitive.... ;)

[identity profile] ratcliffe1963.livejournal.com 2005-02-15 03:58 pm (UTC)(link)
I dunno...you could have people argue both sides of this...I guess it is all in what you are used to, but case insensitivity has made my life a lot easier in numerous ways. I guess you could say it just encourages laziness on the part of the querier/developer...the type of query he is suggesting is probably pretty rare ...
ximinez: (Default)

[personal profile] ximinez 2005-02-15 06:56 pm (UTC)(link)
You say to-may-to. I say to-mah-to.
ximinez: (Default)

[personal profile] ximinez 2005-02-15 03:29 pm (UTC)(link)
Wait a sec, if upper doesn't work, then how would looping through all the lower case letters work?

[identity profile] sylvar.livejournal.com 2005-02-15 03:33 pm (UTC)(link)
CHARINDEX(CHAR(97), @TEXT)
CHARINDEX(CHAR(98), @TEXT)
CHARINDEX(CHAR(99), @TEXT)...
ximinez: (Default)

[personal profile] ximinez 2005-02-15 06:56 pm (UTC)(link)
Ow ow ow ow ow ow ow ow ow ow