2

如果值不为空,我试图在其中输入一个空格,但它似乎只在我运行查询时输出一个数字?

CONCAT(address, IF(address2 = '', '', ' ' & address2), ' ', city, ', ', state, ' ', zip) AS theAddress

上面的查询输出是:

1234 N. Shore Ave.0 Burbank, CA 41577

输出应如下所示:

1234 N. Shore Ave. Apartment 223 Burbank, CA 41577

我会在这里做错什么?

4

2 回答 2

4

试试这个:

CONCAT(address, IF(address2 = '', '', CONCAT(' ', address2)), ' ', city, ', ', state, ' ', zip) AS theAddress

我认为您的代码正在做的是空间和地址2之间的逻辑与

于 2012-08-16T15:08:58.903 回答
2

我认为应该是另一个concat&

CONCAT(address, IF(address2 = '', '', CONCAT(' ',  address2)), ' ', city, ', ', state, ' ', zip) AS theAddress
                                         ^ here

' ' & address2返回 0 和 1(真或假)

于 2012-08-16T15:08:37.590 回答