Return the Current Workstation Name that’s Connected to SQL Server (T-SQL)

Occasionally you might find yourself in the situation where you need to get the name of the current workstation that’s connected to SQL Server.

For example, maybe you have a stored procedure that inserts data, and you want to record the name of the workstation that inserted the data.

In such cases, you can use the HOST_NAME() function.

This is not to be confused with getting the server name.

Continue reading

Remove Duplicates when using $unionWith in MongoDB

In MongoDB, the $unionWith aggregation pipeline stage performs a union of two collections, and it includes duplicates.

This behaves in a similar way to SQL’s UNION ALL, which also includes duplicates. By contrast, using just UNION (i.e. without the ALL)in SQL removes duplicates.

In MongoDB, we don’t have the option of specifying $unionWith ALL or similar, so we need to reduce duplicates in another way.

In MongoDB, we can remove duplicates by using the $group stage.

Continue reading

SET SQLBLANKLINES: How to Allow Blank Lines in SQLcl & SQL*Plus

If you’re trying to run a multi-line query in SQLcl or SQL*Plus, and you keep getting an error such as “Unknown Command”, but running it in SQL Developer causes no such error, maybe this post will help.

By default, SQLcl and SQL*Plus don’t allow blank lines in SQL statements. However, you can change this with the SET SQLBLANKLINES command.

Continue reading

8 Functions to Return the Day from a Date in MariaDB

MariaDB has quite a number of functions that return the day from a date. It all depends on how you want to do it, and what you mean by “day”.

MariaDB needs to know whether you want the day name, the day of the week number, the day of the month, day of year, etc.

Below are 8 functions that enable you to return the day from a date in MariaDB, in its various forms.

Continue reading

SET NULL: Specify a String to Return Whenever a Null Value Occurs in SQLcl / SQL*Plus

SQLcl and SQL*Plus are command line interfaces for working with Oracle Database.

By default, they return an empty string whenever null occurs as a result of a SQL SELECT statement.

However, you can use SET NULL to specify a different string to be returned. Here I specified that the string null should be returned.

Continue reading