Ran across a surprising SQL Server thing today: I was updating a query If you run a query that returns no rows and use the MIN() aggregate function, you get an empty resultset as expected, but the @@ROWCOUNT variable is set to 1. If you write the query as a TOP(1) query in a situation where it returns no rows though, you still get an empty resultset but @@ROWCOUNT is set to zero as expected.
Example of this in action (tested on SQL Server 2012):
CREATE TABLE MyTable(MyId INTEGER, MyName NVARCHAR(128));
SELECT MIN(MyId) FROM MyTable WHERE MyName LIKE 'MyTag'
IF @@ROWCOUNT <> 0 PRINT 'Nonzero row count' ELSE PRINT 'Zero row count' --Output: Nonzero row count
SELECT TOP(1) MyId FROM MyTable WHERE MyName LIKE 'MyTag' ORDER BY MyId
IF @@ROWCOUNT <> 0 PRINT 'Nonzero row count' ELSE PRINT 'Zero row count' --Output: Zero row count
DROP TABLE MyTable;
How to have some roman numeral page numbers and some arabic page numbers in an existing document in LibreOffice
I needed to format an existing LibreOffice 4.3 document to have some beginning pages with no page numbers, then some pages numbered with roman numerals (i, ii, iii…), then the rest of the pages numbered with arabic numerals (1, 2, 3…). Here’s how you do it.
1. Create a page style that will do roman numeral page numbers in the footer
1.1. Go to Format -> Styles and Formatting (or press F11)…
We currently use Drupal OpenChurch for our church website. On the sermon podcast page, any time there was a long sermon title the “play mp3 file” link would overwrite some of the text of the title, looking ugly:
Read the rest of this entry »
To clear the cache on Oracle:
ALTER SYSTEM FLUSH BUFFER_CACHE;
ALTER SYSTEM FLUSH SHARED_POOL;
To clear the cache on SQL Server:
When you’re installing SQL Server (2008 R2 in my case) and you are prompted whether you want to create a default instance or a named instance, understand that creating a named instance means that you will be required to add that instance name to the server name when you connect via SQL Server Management Studio (SqlServerName\InstanceName). If you want to be able to connect to your instance without having to specify it explicitly, create a default instance. Then you just connect to SqlServerName and it finds the default instance.
In a post titled Life, Death, and Splitting Secrets, Jeff Moser presents a software solution for splitting up a password N ways so your loved ones can put the secrets together and get access to critical information from you after your death, using a computer program.
While this shared secret approach is interesting for certain uses, it is unwise for Moser’s stated use… Read the rest of this entry »
We have a table that can have tens or hundreds of millions of rows in it, and in this table there is a certain column. This column usually—typically—generally—has non-null hash values in it.
In unusual cases though, that column can be NULL. And the thing is, there are times when the interesting rows, the rows we want to gather together and do something with, are exactly the rows where that column is null.
Table scans to find the rows where the column is NULL are expensive, so naturally we want to index this column. But since non-null values in this column are a hash and we only ever care about the NULL values, we’d like to avoid the time and space overhead of indexing the non-null values. We’d like a partial index of only the rows where the column is NULL… Read the rest of this entry »