Posts Tagged ‘sql’

Quick and Easy T-SQL Split Statement

June 25, 2009 Leave a comment


Here’s a quick and easy Split function to split a comma separated list (for example, although it could be separated with any character) into a table that can be easily joined in the calling statement.

The only bad news here is that you will need SQL 2005 or above for this to work (if my memory serves me correctly) – but then if you’re still running SQL 2000 one has to beg the question, ‘Why?’. 

Anyway – over to the code:

create function Split ( @StringToSplit varchar(2048), @Separator varchar(128))
table as return
indices as
    select 0 S, 1 E
    union all
    select E, charindex(@Separator, @StringToSplit, E) + len(@Separator)
    from indices
    where E > S
    select substring(@StringToSplit,S,case 
        when E > len(@Separator) then e-s-len(@Separator) 
        else len(@StringToSplit) - s + 1 end) String, S StartIndex 
        indices where S >0

Categories: SQL Server Tags: ,

Location of SQLCMD and SQLPubWiz Executables

June 18, 2009 Leave a comment

T-SQLEver needed the SQL Publishing Wizard as a stand-alone install for a build server – I did and finally found it here:

SQL Publishing Wizard:

You might find you want a copy of SQLCMD.EXE too, it’s here:

Categories: SQL Server Tags: ,
%d bloggers like this: