Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merging Blank Columns

Status
Not open for further replies.

KempyLims

Programmer
Joined
Jan 20, 2004
Messages
1
Location
EU
I have a table containing Customer information.
Not all of these columns have data in them for example:

________________________________________________________
Company : Address1 : Address2 : Address3 : Address4 :Add5
compa : 1 street : : Suffolk : UK :fgfgf
compb : 3 Road : Top Hill : Norfolk : dfdfdf :

What i need to do ( somehow) is to create a select query that ignores the blank columns and only returns the cols with data in them. Concatenating the cols together does not cure the problem, as if there are 2 blank cols next to each other then you end up with a blank row with a ',' on it.
Is there are way to 'shuffle' the cols up so only those with data in them get returned?

Any help would be appreciated.

 
Depends on your DB. If it supports case/decode then you can do something like ...
Code:
select company,
case when address1 is not null then address1 end +
case when address2 is not null then address2 end +
case when address3 is not null then address3 end +
case when address4 is not null then address4 end +
case when address5 is not null then address5 end
+ is the concatenation operator.

Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top