Click here to Skip to main content
14,937,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Comments
VishwaKL 6-Jul-15 1:34am
   
Is those are database values/ drop list values?

if they all database values, read the selected string in drop down selected value event and concatenate or format the string how you need, and display
xpertzgurtej 6-Jul-15 1:40am
   
These are database values and i want to get single concatenated field

1 solution

Hi,

Check this....


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


or

SQL
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
   
v2
Comments
xpertzgurtej 6-Jul-15 1:39am
   
Not workoing as required..It is displayinh -> where there are Nulls
Magic Wonder 6-Jul-15 1:47am
   
Isnull() should work. Can you give me some sample data and output?
Magic Wonder 6-Jul-15 1:50am
   
Oh!!! Well isnull(City,'') will replace null with blank(''). So if you want to replace it with some default value you can use ISNULL(CITY,'DELHI').
Magic Wonder 6-Jul-15 1:57am
   
Check updated solution.
xpertzgurtej 6-Jul-15 2:06am
   
thanks magic wonder your updated solution was awesome..:).. Can you please also suggest if country is also nullable then what changes are reuired?
Magic Wonder 6-Jul-15 2:13am
   
Your welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900