none
Create insert statement issue.

    Question

  • Hi,

    I have a need to create insert statement where more that 500 columns playing vital role.

    My Current approach is-

    DECLARE @InsertString VARCHAR(max);

    SET @InsertString = 'Insert into IP_TEST (Date_Created, and so on till 500+ columns .....values (';

    select 

    @InsertString +

    ''''+ case when a.Date_Created is null then '' else Replace( a.Date_Created,'''', '''''') end + ''''+ ','+

    ''''+ case when a.Universal_ID is null then '' else Replace( a.Universal_ID,'''', '''''') end + ''''+ ','+

    ''''+ case when TestAppAssessComments is null then '' else Replace( TestAppAssessComments,'''', '''''') end + ''''+ ');'

    from

    IP_TEST a

    With following above approach not able to get insert statement for more that 500 columns.

    Is there any other suggested approach where i can get all insert statement in one stroke.

    Currently i am getting below error-

    The query processor ran out of stack space during query optimization. Please simplify the query.

    Please suggest, many thanks.!


    • Edited by Maggy111 Tuesday, October 22, 2013 7:49 AM
    Tuesday, October 22, 2013 7:44 AM

All replies