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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concatenate with parentheses around a column

Status
Not open for further replies.

JustATheory

IS-IT--Management
Feb 27, 2003
115
US
I have a concatenation problem. I can get the left parentheses to display but not the right. Here is what should happen, if column 2 is populated the concatenate col1 with parens around col2. If col2 is null then concatenate col1 with parens around a dash. It functions properly for placing the das in the field, I’m just having trouble closing the paren. Help is always greatly appreciated. Please see example.


Thanks,
JustATheory


col1 || '('|| NVL(col2,'-') || ‘)’ || as NewCol,

Result should be:

Rec NewCol

1 Data1 (Data2)
2 Data1( - )
 
If you want to write ANSI SQL, use [tt]COALESCE[/tt] instead of NVL.

Your concatination seems to need a minor correction, remove the last ||, i.e.[tt]
col1 || '(' || COALESCE(col2,'-') || ')' as NewCol,[/tt]
 
Hi JarlH,

That was it! Many thanks!


Thanks,
JustATheory
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top