How SQLite Count() Works

The SQLite count() function can be used to return the number of rows in a result set.

It can also be used to return the number of times a given column is not NULL in the result set.

It can be used in two ways. If you pass in the asterisk (*) wildcard character, it will return the total number of rows in the group. If you provide the name of a column, it will return the number of times that column is not NULL.

Continue reading

What is @@SERVICENAME in SQL Server?

In SQL Server, the @@SERVICENAME configuration function returns the name of the registry key under which SQL Server is running.

No argument is required. You can simply use it in a SELECT statement to return the registry key’s name.

Note that SQL Server runs as a service named MSSQLServer. The @@SERVICENAME function returns MSSQLSERVER if the current instance is the default instance. It returns the instance name if the current instance is a named instance.

Continue reading

Introduction to User-Defined Functions in SQL Server

SQL Server ships with a collection of built-in functions that enable you to perform a variety of operations. Each built-in function serves a specific purpose, and can’t be modified. If a function serves your purpose, you can go ahead and use it.

But what if you can’t find a function that serves your purpose?

Then it’s time to write your own user-defined function.

Continue reading