in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

How to merge two columns

Last post 05-06-2009 11:56 PM by ammsamm. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 05-05-2009 8:06 AM

    How to merge two columns

    I have 3 text columns
    ------------------------
    Col1      Col2      Col3
     A            B          AB    
     C            D          CD
    -------------------------
    How to merge Col1 and Col2 to be like Col3

    i did try " update mytable set Col3 = Col1 + Col2  "

    but it did't work
    Thanks

  • 05-05-2009 9:35 AM In reply to

    Re: How to merge two columns

    In SQLite, to concat two strings, use double-pipes:

    update mytable set col3 = col1 || col2

     

  • 05-05-2009 12:04 PM In reply to

    Re: How to merge two columns

    Thanks Robert it's works just fine ...

    but one more thing ..

     if i whant to concat col1 ,col2 and col3 and there is some empty cells in col3

    it don't concat

  • 05-05-2009 1:06 PM In reply to

    Re: How to merge two columns

    Did it with

    update mytable set name = col1 || " " || col2 where col3 isnull

  • 05-06-2009 11:45 PM In reply to

    • Knch
    • Top 50 Contributor
    • Joined on 02-10-2009
    • Posts 30

    Re: How to merge two columns

    You could have used functions ifnull(X,Y) or coalesce(X,Y,...) (See http://www.sqlite.org/lang_corefunc.html for details)

    UPDATE mytable SET name = col1 || ifnull ( col3 , " " ) || col2

  • 05-06-2009 11:56 PM In reply to

    Re: How to merge two columns

    Thanks i'll keep your post in mind

Page 1 of 1 (6 items)
Powered by Community Server (Commercial Edition), by Telligent Systems