Split()-like string-to-array function in Transact-SQL

Uncategorized 5 Comments »

Transact-SQL doesn’t have arrays or nifty string functions like the C# System.String.Split () or java’s String.split() returning arrays in one swoop. Then again, SQL knows the SELECT … IN statement like

SELECT * FROM table1 WHERE id in (1,2,3,526) 

so why no looping through comma-delimited strings?

A “Table-valued User-defined Function” returning a table variable is a handy and versatile workaround letting you query and loop through the values with near array-like ease.

The code could look like this:

CREATE FUNCTION [dbo].[StringToTable] ( @inputString nvarchar(max), @separator char (1) ) RETURNS @ResultTable TABLE ( [String] nvarchar(max) ) AS BEGIN DECLARE @stringToInsert nvarchar (max) WHILE LEN(@inputString) > 0 BEGIN SET @StringToInsert = LEFT( @inputString, ISNULL(NULLIF(CHARINDEX(@separator, @inputString) - 1, -1), LEN(@inputString) ) ) SET @InputString = SUBSTRING(@InputString, ISNULL (NULLIF (CHARINDEX(@separator, @InputString), 0), LEN(@InputString)) + 1, LEN(@InputString)) INSERT INTO @ResultTable ( [String] ) VALUES ( @StringToInsert ) END RETURN END

Again, the Transact-SQL string functions seem clumsy and inadequate compared with high-level languages. Short of using CLR functions in the database table-valued functions can put custom string operations at your immediate disposal.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Perl Help CHM

Uncategorized 1 Comment »

Compiled HTML help for Perl is here, well written and easy to read. The very useful link contains much other stuff too.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Microsoft perfidious - printer-(un)friendly politics

Uncategorized No Comments »

Yes, Microsofts web site has some interesting content, such as this article. As I like to print stuff to PDF to read on my PDA, I will usually search all over for a “printer-friendly” link immediately. Alas, while MS pages have one in IE (Internet Explorer),

no such luck in Firefox:

 

nor the weirdo of browsers, Opera:


So, to print the page, simply add “?pf=true” to the end of the URL so http://www.microsoft.com/windowsxp/using/digitalphotography/prophoto/gps.mspx becomes http://www.microsoft.com/windowsxp/using/digitalphotography/prophoto/gps.mspx?pf=true
Beat MS at their own game. Hope it helps.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Alt + Tab Task Switcher with clickable icons

Uncategorized No Comments »

Goheer has created a very nifty utility to greatly improve on the windows task switcher (Ctrl + T) with clickable icons and thumbnails of the open windows. There is also a power toy doing something similar but why use MS when you can avoid it? One more reason not to upgrade to Vista. 

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Justin starts blogging

Uncategorized No Comments »

More soon on flickr.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in