<cfwhat>

Thursday, July 26, 2012

Recursive Queries Using Common Table Expressions

Just started playing with recursive Queries in SQL2008. Microsoft has some useful documentation.zzz

Thursday, July 05, 2012

List manipulation in SQL

Here are a three functions for list manipulation using SQL.

@RowData is the name of a column.
@SplitOn is the list delimiter (eg comma, period, space etc)

Get the first item:
ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))

Get the last item:
right(@RowData, charindex('.', reverse(@RowData), 1) - 1)

Get the list without the first item:
Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))

These are the equivalent of ColdFusion's ListFirst(), ListLast() and ListRest() functions.