• murthyvs (12/14/2012)


    Hi - the solution works as expected. Is there anyway to increase the size of the input string to 100,000. Its only limited to 8,000.

    Thanks much!

    Unless your example is just a striking coincidence, I've seen such a thing before and I'd like to make a totally alternate suggestion if what I suspect is actually true.

    It would appear that both fields in the string are sequential in their own right. If that is true (as it was with what I've seen before), then it will save you a huge amount of aggravation, the server a huge amount of processing time and I/O, your network an unnecessary blurb of 100K bytes for each usage, and the loss of feeling in your left arm when everyone jumps on you for resource usage, if you were to send just a starting value for each field and the number of field-pairs and let SQL very quickly generate even millions of pairs more quickly than you could ever transmit them.

    For example, your example has fields that start with 30 and 38469 respectively and then both increment by 1 for 9 pairs of fields. Using the method I proposed above, you would pass only those 3 parameters over the pipe and then let SQL Server have at it. That would be capable of generating millions of rows if you needed it an it would happen a whole lot quicker than trying to send a million such field pairs over the pipe. For example, here code that does what I said o a million rows. I believe you'll find it to be remarkably quick.

    --===== These would be parameters in a stored procedure

    DECLARE @F1Start INT,

    @F2Start INT,

    @Pairs INT

    ;

    SELECT @F1Start = 30,

    @F2Start = 38469,

    @Pairs = 1000000

    ;

    --===== This would do the deed as previously described.

    WITH

    cteTally AS

    (

    SELECT TOP (@Pairs)

    N = ROW_NUMBER() OVER (ORDER BY (SELECT NULL))-1

    FROM master.sys.all_columns ac1

    CROSS JOIN master.sys.all_columns ac2

    )

    SELECT Field1 = @F1Start + N,

    Field2 = @F2Start + N

    INTO #Temp

    FROM cteTally

    ;

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)