• Hugo Kornelis (11/29/2011)


    INSERT INTO #ATable

    (col1, col2, col3)

    SELECT 2, 1, 3;

    (Where I change the column positions based on the length of the column names and expressions in the SELECT list).

    I usually limit myself to three columns per line, because I don't like to scroll horizontally. So when there's a long column list, I use this style:

    INSERT INTO #BTable

    (col1, col2, col3,

    col4, col5, col6,

    col7, col8)

    SELECT 2, 1, 3,

    4, 5, 6,

    7, 8;

    That's a great advice. In my day job, I can see, in many codes, a long list of columns without proper formatting and it gets harder and harder to read once the table's structure changes and you need to update code.

    I usually code my INSERTs like this whenever possible:

    INSERT INTO #ATable

    (

    Col1,

    Col2,

    Col3

    )

    VALUES

    (

    2 AS Col1,

    1 AS Col2,

    3 AS Col3

    );

    I'm not sure if it's a good way of doing it but it looks clear to me. 🙂

    Best regards,

    Best regards,

    Andre Guerreiro Neto

    Database Analyst
    http://www.softplan.com.br
    MCITPx1/MCTSx2/MCSE/MCSA