How to break up a varchar variable into bite sized chunks

  • I've got a varchar variable of indeterminate length which I need to break up into chunks of no more than 150 characters, but I also don't want it to split in the middle of a word or number.

    The first question is wether T-SQL can handle array variable like visual basic, something like @details(1) @details(2) @details(3) without having to predefine each one?

    If so, I think I can use a cobination of CHARINDEX and LEFT to take the first 150 characters then work back to a blank space, then loop until the there's less than 150 characters left in the original variable.

    If there isn't then I'd love to hear some ideas. I suppose I could declare all the variables for all conceivable parts, but the original variable could be up to 4000 characters, and given that it will be split at 150 or less, it's a lot of variables to declare and pretty ugly.

    Thanks,

    Mark

  • You have got the logic right. Just sprinkle some more checks for sentences detection and you got what a typical VB6 programmer ( like me ) would do ... no offense ... Infact i have just this implementation in VB6.

    The solution that you present here is quite what you need.

    But for a deeper thought we have quite a # of gurus here like Sergie and Jeff.

    Just top of my head ... you can have a table datatype to help you out ... i am working on it and if i find something good; i'll post it here !


    FP

    True Love is Like A Ghost. Everyone Talks About It & Nobody have seen it.

  • I believe if you'll split by words it's not gonna have chunks more than 150 characters.

    You may use UDF posted here:

    http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=310562&p=4

    to split any string into words.

    P.S. "Array" means "Table" in database world.

    _____________
    Code for TallyGenerator

  • > But for a deeper thought we have quite a # of gurus here like Sergie and Jeff.

    Guru's suck.

    Would not say about every one, but pretty sure about the one having name started from "S".

    _____________
    Code for TallyGenerator

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply