30 September 2016

The power of firstOnly keyword

Sometimes only one record from a table is required, but firstOnly keyword is not used by a developer. For example:
select AccountNum from custTable
    where custTable.CustGroup == '10';

if (custTable.AccountNum)
{
    ...
}
What difference does it make?

Problem description
Compare select statements with and without firstOnly keyword.

Hints
Use SQL Server Profiler for analysis and trace RPC:Starting and RPC:Completed events: