Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005
    Posts
    74

    Unanswered: Combined result...

    hi! can anybody please help me...what would be my query string if i want to combine 3 column into one column?
    example. I have 3 columns in my customer table namely street,City,postal_code and i want to query that 3 column as address having it combined. thanks in advance.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    well, daimous, it seems like you did not understand why i moved your previous thread to the microsoft SQL Server forum

    so here is the SQL answer --
    Code:
    select street||City||postal_code as address
      from yourtable
    if you find that this doesn't work in SQL Server, i trust it will bring to your attention that SQL Server questions should be posted in the SQL Server forum and not the SQL forum

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2003
    Location
    Pittsburgh, PA
    Posts
    86

    In SQL Server

    Try this

    Code:
    Select [street]+',  '+[city]+' '+[postal_code] as Address
    from YourTable
    This assumes that you have [postal_code] defined as a varchar, and not an integer or numeric field. I put in some spaces and a comma, so your output would be something like this:

    Street, City Postal_Code

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    If you have NULL values in your table and are using default SQL Server settings, you may need to use this:

    Select coalesce([street]+', ', '')+Coalesce([city]+' ', '')+Coalesce([postal_code], '') as Address
    from YourTable

    Now, go open up Books Online and read about concatenation and the COALESCE function.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •