The ‘Database’ Archives
Posted February 19, 2013 by

SQL Server 2012: How to Use IIF() Logical Function

mssql-logo

SQL Server 2012 has introduced the new logical function IIF(). The behavior of function IIF() is quite similar to CASE and IF statements in SQL Server. Using IIF(), you can use fewer lines of code, and your code will be more readable.

Category Database

Posted February 9, 2013 by

SQL Server: Execute SQL Script Using SQLCMD Command Line

mssql-logo

SQLCMD command line Utility is an alternative way to execute SQL scripts using the command line. This allows us to execute SQL scripts without touching SQL Server Management Studio (SSMS) GUI.

Category Database

Posted January 31, 2013 by

SQL Server 2012: How to Use CHOOSE() Logical Function

mssql-logo

SQL Server 2012 introduced the powerful new CHOOSE() function. This tech-recipe will explore its use and common mistakes through some simple examples.

Category Database

Posted January 28, 2013 by

SQL Server: Check if Table or Database Already Exists

mssql-logo

Errors warning that “there is already an object” and that the “database already exists” can easily be avoided by first determining if your table and database have already been created.

Category Database

Posted October 23, 2012 by

SQL Server: Copy One Table to Another Using Stored Procedure

Stored Procedure to copy one table to another.

When modifying an important table in the database, user frequently backup the table by making a copy of the original table with a different name. Using a stored procedure makes this process simple and convenient to reuse.

Category Database, SQL Server

Posted October 14, 2012 by

SQL Server: How to Left Pad a Number with Zeros

mssql-logo

The replicate T-SQL function in Microsoft’s SQL Server makes it simple to add leading zeros to a number value.

Category Database, SQL Server

Posted October 7, 2012 by

SQL Server: How to Swap Values between Two Columns

sql-feature

When working with databases, moving and swapping values between columns is a common task.

Category Database, SQL Server

Posted September 20, 2012 by

SQL Server: How to Check if a File Exists in a Directory

mssql-logo

Frequently, when working with SQL, we need to know if a file exists in a local directory or not. This can be done using SQL Server’s built-in procedure known as master.dbo.xp_fileexist. This user-defined function (UDF) checks whether or not a file exists in a specified directory.

Category Database, SQL Server

Posted September 13, 2012 by

SQL Server: Use a CASE Expression in an Update Statement

mssql-logo

The CASE expression is used to compare one expression with a set of expressions in SQL. The result of the CASE expression is a Boolean value, true or false. We can use various DML statements like INSERT, SELECT, DELETE and UPDATE with a CASE statement. In this Tech-Recipes tutorial, we will see how to use […]

Category Database, SQL Server

Posted June 3, 2012 by

SQL Server: Generate Insert Statement Script

sql-feature

When running reports, for example, the same insert statements need to be created over and over again. SQL Server includes a great feature to generate these insert statements automatically.

Category Database, SQL Server