本文介绍了如何将国家,州和城市连接为国家 - >州 - >市的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表格中有3列。国家,州,城市。州和城市可以为空。我想将名为location的连接字段显示为:Country - >州 - >市。当州和城市可以为空时如何处理?

I have 3 columns in table. Country, State, City. Here State and City is nullable. I want to show concatenated field named location as: Country -> State -> City. How to handle this when state and city is nullable?

推荐答案

Select ISNULL(COUNTRY,'') + '->' + ISNULL(STATE,'') + '->' + ISNULL(CITY,'') As Addr from your table











or

Select
CASE WHEN ISNULL(COUNTRY,'')='' THEN '' ELSE COUNTRY END  +
CASE WHEN ISNULL(STATE,'')='' THEN '' ELSE + '->' + STATE  END +
CASE WHEN ISNULL(CITY,'')='' THEN '' ELSE + '->' + CITY END
As Addr from your table







希望这会对你有所帮助。



干杯




Hope this will help you.

Cheers


这篇关于如何将国家,州和城市连接为国家 - >州 - >市的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:23
查看更多