Author Archives: Aaron

SQL – Select into XML structure

from imp_dataSource d
join def_mapping m on m.sup_propertyCode = d.sup_propertyCode
where m.sup_familyCode = d.sup_familyCode or m.sup_familyCode ='GENERIC'
and m.map_type in ('SIMPLE', 'COMPLEX')
and d.sup_propertyValue != '' and d.sup_propertyValue is not null
order by d.sup_familyCode, d.sup_productCode, d.sup_propertyCode
for xml auto, type, elements, root('Products')

MS SQL – Removing non-printable characters

XPath – Find nodes with attribute of value X

Practical example from TradeXML, finding all nodes with attribute name == CONSTR_TYPE:


SQL select on XML type column

SELECT column
FROM table
where column.value(‘(/xpath/expression/parameter[@name=”supplierID”])[1]’, ‘nvarchar(100)’) = ‘matchValue’

Access Tutorials


Excel Lookup Lists with Tables

Good article on Excel lookup validations using a table column as the value source:

SQL Case-sensitive select statement

If Column1 of Table1 has following values ‘CaseSearch, casesearch, CASESEARCH, CaSeSeArCh’, following statement will return you all the four records.

SELECT Column1
FROM Table1
WHERE Column1 = 'casesearch'

To make the query case sensitive and retrieve only one record (“casesearch”) from above query, the collation of the query needs to be changed as follows.

SELECT Column1
FROM Table1
WHERE Column1 COLLATE Latin1_General_CS_AS = 'casesearch'

Adding COLLATE Latin1_General_CS_AS makes the search case sensitive.

Default Collation of the SQL Server installation SQL_Latin1_General_CP1_CI_AS is not case sensitive.

To change the collation of the any column for any table permanently run following query.

COLLATE Latin1_General_CS_AS

To know the collation of the column for any table run following Stored Procedure.

EXEC sp_help DatabaseName

Second results set above script will return you collation of database DatabaseName.

Reference : Pinal Dave (