语法不正确.你想使用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
结果
| LOC_INFO |
-----------------------------------------------
| Location
10 Add Street
City, State Country
|
只需找到并替换@.