Skip to content

SQL Bits

You're here to find quick SQL recipes.

  • Home
  • Topics
    • Generic SQL
    • PostgreSQL
    • MariaDB
    • MySQL
    • Oracle
    • SQL Server
    • Db2
    • Informix
    • SQLite
  • Advertising
  • Write
  • About

Category: SQL Server

SQL Server: Find users login time

Finding users who never logins is not trivial in SQL Server. But we can do it by creating a logon trigger.

Continue reading SQL Server: Find users login time
Published December 2, 2021
Categorized as SQL Server Tagged level-intermediate

SQL Server: Writing an HTML encode function

Sometimes we need to extract a text from the database to show it in a web page. The text should be showed as is, including any HTML tags and special characters. Normally the encoding is done by a web application, but there are cases when an SQL string is expected to return HTML encoded texts.

Continue reading SQL Server: Writing an HTML encode function
Published November 28, 2021
Categorized as SQL Server Tagged level-intermediate

SQL Server: How to count occurrences of a substring in a string

Sometimes you want to count all occurrences of a substring into a bigger string. For example, you may want to count all occurrences of a name in a text. This can be done, but it’s not straight-forward because SQL Server doesn’t have a specific function to do it.

Continue reading SQL Server: How to count occurrences of a substring in a string
Published November 11, 2021
Categorized as SQL Server Tagged level-intermediate

SQL Server: Concatenate strings (NULL-safe)

There are several ways to concatenate strings in SQL, and they mainly differ in how they handle NULL values.

Continue reading SQL Server: Concatenate strings (NULL-safe)
Published October 24, 2021
Categorized as SQL Server Tagged level-beginner

Creating UNSIGNED columns in SQL Server

Some DBMSs, like MariaDB and MySQL, allow to create UNSIGNED columns. SQL Server doesn’t support unsigned integers. Let’s see what we can do instead.

Continue reading Creating UNSIGNED columns in SQL Server
Published October 22, 2021
Categorized as SQL Server Tagged level-intermediate

SQL Server: Handle errors

SQL Server allows to handle errors with TRY ... CATCH blocks, and provides several statements to get information about the error that is being handled.

Continue reading SQL Server: Handle errors
Published October 9, 2021
Categorized as SQL Server Tagged level-intermediate

SQL Server: Raise errors and warnings

Transact-SQL provides facilities to raise errors and warnings, as well as handling them. Here’s an introduction to this subject.

Continue reading SQL Server: Raise errors and warnings
Published September 22, 2021
Categorized as SQL Server Tagged level-expert

SQL Server: CHECKSUM() vs CHECKSUM_BINARY() vs HASHBYTES()

SQL Server has at least three functions to create checksums or hashes: CHECKSUM(), CHECKSUM_BINARY(), and HASHBYTES(). Here we discuss what differences exist between them, and how to choose the proper function for a specific use case.

Continue reading SQL Server: CHECKSUM() vs CHECKSUM_BINARY() vs HASHBYTES()
Published August 22, 2021
Categorized as SQL Server Tagged level-intermediate

SQL Server extended properties (comments)

Most DBMSs allow to read and write comments about tables, columns and other database objects. SQL Server has a more complex feature called Extended Properties.

Continue reading SQL Server extended properties (comments)
Published August 9, 2021
Categorized as SQL Server Tagged level-intermediate

SQL Server: Send alerts via email

Sometimes we want to send an email when something suspicious happens in a database. SQL Server is able to natively send emails.

Continue reading SQL Server: Send alerts via email
Published July 26, 2021
Categorized as SQL Server Tagged level-expert

Posts navigation

Page 1 Page 2 Older posts
  • Twitter
  • Email
SQL Bits
Proudly sponsored by Vettabase.