Combining Two Excel Columns in One Column in SQL

  • Good morning community,

    I have a task at hand that I'm a little puzzled on how to accomplish. I have an excel worksheet that has 80,096 counties across the US. Along with those counties are the states in which they reside. For example:

    Column A Column B

    State County

    NY SUFFOLK

    PR ADJUNTAS

    PR AGUADA

    PR AGUADILLA

    MN MOWER

    PA SUSQUEHANNA

    MT GLACIER

    UT GARFIELD

    KY LESLIE

    MO SHELBY

    SD CORSON

    VA LOUDOUN

    IL KANKAKEE

    What I need to do is write an insert statement similar to this:

    INSERT INTO [TOWN_CODE] ( [SYS_ID] , , [DESCRIPTION] , [DISCONTINUED] , [SYSTEM_CODE] , [CREATE_TIMESTAMP] , [MODIFY_TIMESTAMP] , [CREATE_USER] , [MODIFY_USER] )

    VALUES ( SUBSTRING(REPLACE(NEWID(),'-',''),1,32), '0016', 'WI ADDISON', 'F', 'F', '4/6/2010 3:30:34 PM', '4/6/2010 3:30:34 PM', 'SYS_USER', '');

    Where I become perplexed is in the field of description. My client wants the two character state code and a space to precede the county name in the same field. So I need to know if I can use SQL to insert column A and column B from Excel into one column [DESCRIPTION] in SQL.

    I understand that this might be an Excel question and NOT necessarily a SQL question, so I apologize up front if I offend anyone. I did find an article that might work, but I'm not too sure. Any thoughts or comments would be greatly appreciated. Thank you. 😀

    (

    this might work if I place my data into a temporary table...

    http://www.sqlservercentral.com/Forums/Topic699124-8-1.aspx

    )

  • It would be much easier of you perform this task after the table is loaded, then you have a simple update statement.

    Then all you have to do is write a simple UPDATE statement to fill in what ever you like.

    UPDATE

    <TableName>

    SET

    <ColumnName>

    = StateAbbrevationColumn +' '+ CountyNameColumn

    Andrew SQLDBA

  • So sorry for the delay in my response... We are so close to the completion of this project. This worked like a charm. Thank you very much for your help...:-D

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

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