Archive

Posts Tagged ‘sql’

Quick and Easy T-SQL Split Statement

June 25, 2009 Leave a comment

T-SQL

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))
returns 
table as return
with 
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 
    from
        indices where S >0

Advertisements
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: http://www.microsoft.com/downloads/details.aspx?FamilyId=56E5B1C5-BF17-42E0-A410-371A838E570A&displaylang=en

You might find you want a copy of SQLCMD.EXE too, it’s here: http://www.microsoft.com/downloads/details.aspx?familyid=d09c1d60-a13c-4479-9b91-9e8b9d835cdc&displaylang=e

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