devxlogo

SQL

Find Tables with an XML Column

You can find tables with an XML column in the following way: SELECT [table] = s.name + N’.’ + t.name FROM sys.tables AS t INNER JOIN sys.schemas AS s ON

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.