devxlogo

SQL

Obtain the Oldest Open Transaction

You can obtain the oldest Open Transaction in the following way: — Create temporary table for results. CREATE TABLE #OpenTrans ( CurrTrans VARCHAR(25), CurrTransDet SQL_VARIANT ); — Insert info in

Compare Only Alphabetic Values

You can force a like condition to compare only alphabetic values. Here is how: ORDER BY CASE WHEN LTrim(RTrim(Place.Name)) NOT LIKE ‘%[^0-9]%’ THEN 1 ELSE 2 END, Place.Name

Fetching Common Records Between Two Tables

You can fetch records that are common to one or more tables by using INTERSECT. Here is a small example: Select * from EmployeesIntersectSelect * from RetiredEmployees

Setting a Default NULL Date in SQL

Setting a default NULL Date in SQL is quite easy, you just need to concentrate. A statement similar to the following will convert any NULL value inside the specific DATE

SET ARITHABORT ON

Dramatically reduce the execution speed of your queries using SET ARITHABORT ON as it saves time by not calculating unnecessary numerical data.

Import Excel Data into SQL

In order to read from an Excel Spreadsheet through SQL you need to install the Office 2010 Database Engine. Afterwards, run statements similar to the following: EXEC sp_configure ‘Show Advanced