Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9240601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:13:01+00:00 2026-06-18T08:13:01+00:00

I’m trying to do something I thought would be simple, but I’m stuck. I

  • 0

I’m trying to do something I thought would be simple, but I’m stuck. I basically want to create a single address field from multiple address part fields, using an IF statement to use either an address or intersection. Here is my statement to make the field:

        CONCAT(loc_name,'\n',
            IF ( add_number != '' && add_street != '' ) THEN 
                CONCAT(add_number,' ',add_street,'\n')
            ELSEIF ( x_street_1 != '' && x_street_2 != '' ) THEN 
                CONCAT(x_street_1,' & ',x_street_2,'\n')
            END IF
        ,city,', ', 
            IF ( state != '') THEN 
                CONCAT(state,' ',country,'\n')
            ELSEIF ( x_street_1 != '' && x_street_2 != '' ) THEN 
                CONCAT(country,'\n')
            END IF
        ) AS loc_info

But it doesn’t like what I am doing at all, it throws an error at:

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') THEN \n\t\t\t\t\t\tadd_number,' ',add_street,'\n'\n\t\t\t\t\tELSEIF ( x_street_1 != '' && x_"

Which seems like it doesn’t like my empty field (”) notation. But I don’t know why. Can I not use the IF statement inside a CONCAT like that?

Thanks for any insight.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:13:03+00:00Added an answer on June 18, 2026 at 8:13 am

    The syntax is not correct. You want to use CASE:

    SET @loc_name = 'Location';
    SET @add_street = 'Add Street';
    SET @add_number = '10';
    SET @x_street_1 = 'Street 1';
    SET @x_street_2 = 'Street 2';
    SET @city = 'City';
    SET @state = 'State';
    SET @country = 'Country';
    
    SELECT Concat(@loc_name, '\n', CASE 
                                     WHEN @add_number != '' 
                                          AND @add_street != '' THEN 
                                     Concat(@add_number, ' ', @add_street, '\n') 
                                     WHEN @x_street_1 != '' 
                                          AND @x_street_2 != '' THEN 
                                     Concat(@x_street_1, ' & ', @x_street_2, 
                                     '\n') 
                                   end, @city, ', ', CASE 
                                                       WHEN @state != '' THEN 
           Concat(@state, ' ', @country, '\n') 
                  WHEN ( @x_street_1 != '' 
                         AND @x_street_2 != '' ) THEN Concat(@country, '\n') 
                                                     end) AS loc_info 
    

    Result

    |                                    LOC_INFO |
    -----------------------------------------------
    | Location
    10 Add Street
    City, State Country
     |

    Just find and replace @ with .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.