Bulk Insert a SQL Statement?

  • I have a data output that looks like this:

    code="sql"]SELECT A+|+B+|+C[/code]

    Output is A|B|C similar to a text file.

    Is there anyway that I can insert A, B, C into a table with a SQL query?

  • imba (1/14/2016)


    I have a data output that looks like this:

    SELECT A+|+B+|+C

    Output is A|B|C similar to a text file.

    Is there anyway that I can insert A, B, C into a table with a SQL query?

    Insert into what?

    You can concatenate them into 1 column or you can update 3 different columns or some other combination.

    Please provide the table definition that you are inserting into and where A, B and C are suppose to go and rules used to determine what gets inserted into what column if needed.

    __________________________________________________________________________________________________________
    How to Post to get the most: http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • The table contains three columns. A B C are always separated by a pipe.

  • imba (1/14/2016)


    I have a data output that looks like this:

    SELECT A+|+B+|+C

    Output is A|B|C similar to a text file.

    Is there anyway that I can insert A, B, C into a table with a SQL query?

    Your reply is still vague and you have not provided the ddl for either table or the rules used to determine what goes where.

    Any Insert statement will do.

    Insert someTable (colA, colB, colC)

    Select 'A', 'B', 'C';

    __________________________________________________________________________________________________________
    How to Post to get the most: http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • imba (1/14/2016)


    I have a data output that looks like this:

    code="sql"]SELECT A+|+B+|+C[/code]

    Output is A|B|C similar to a text file.

    Is there anyway that I can insert A, B, C into a table with a SQL query?

    Yes. Run it through a "splitter" and then pivot the data into separate columns. You can find a pretty good splitter at the following URL.

    http://www.sqlservercentral.com/articles/Tally+Table/72993/

    --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)

  • If there are only three columns, you might want to take a look at today's headline article[/url]. Of course, if this is something you're going to do regularly on large tables, you'll want to run performance comparisons to find out which method is the most efficient.

    John

Viewing 6 posts - 1 through 5 (of 5 total)

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