Change the Separator to a Comma in SQLite Query Results

By default, the SQLite command line shell formats query output as a pipe-separated list, without column headers.

If you need to output the results using commas instead of the pipe-symbol, you can specify this with the .separator dot command.

If you need to format your results as string literals, see How to Enclose Strings in Single Quotes. Or if you need any strings to be enclosed in double quotes, see How to Format Results as CSV.

Continue reading

Format SQLite Query Results as Columns with Column Headers

By default, when you connect to the SQLite command line shell and run a query, the result is returned as a pipe separated list.

You might have noticed that the results don’t include the column names, which can make your results confusing if you’re trying to read them, especially if the query returned many columns.

Fortunately, there’s an easy way to format the output so that it’s displayed as a column with column headers.

Continue reading

How to Use GOTO in SQL Server

In SQL Server, you can use GOTO to alter the flow of execution. You can use it to “jump” to another part in the T-SQL code.

The way it works is, you create a label, then you can use GOTO to jump to that label. Any code between GOTO and the label are skipped, and processing continues at the label.

GOTO statements and labels can be used anywhere within a procedure, batch, or statement block. They can also be nested.

Continue reading

Create a Temporary Table in SQL Server

In SQL Server, temporary tables are created using the same CREATE TABLE syntax as regular tables. The difference is that temporary tables’ names are prefixed with either one or two number signs (#), depending on whether it’s a local temporary table or global temporary table:

  • Local temporary tables are prefixed with a single number sign (#)
  • Global temporary tables are prefixed with a double number sign (##)

Continue reading

How to Encrypt a Stored Procedure in SQL Server

In SQL Server, you can encrypt a stored procedure at the time you create it, or you can alter it later to include encryption.

To create a stored procedure with T-SQL, you use the CREATE PROCEDURE syntax. To encrypt it, you add the WITH ENCRYPTION argument.

You can also use the same argument to encrypt an existing procedure when using ALTER PROCEDURE.

Continue reading