DB2 Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDB2 Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old February 16th, 2006, 03:02 PM
StatusWoe StatusWoe is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Posts: 5 StatusWoe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m 53 sec
Reputation Power: 0
Question Value Gen Formula

Hello,

I was looking for a way to generate a column's value by concatinating the values of 2 other columns in the table (same record). DB2 asks for a "Formula" to do this but I have been thusfar unable to find the syntax of such a formula. A link to what sort of "Formula" they are looking for and possibly the formula's syntax would be greatly appreciated.

Thanks for your time.

-Brent

"I need more practice at getting things right the first time"

Reply With Quote
  #2  
Old March 7th, 2006, 08:07 PM
vnquoi vnquoi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 3 vnquoi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 21 sec
Reputation Power: 0
try this:

SELECT (column1 + column2) AS newColumn FROM TABLEX

or

SELECT
CASE WHEN column1 > 0 and column2 > 0 THEN
column1 + colmn2 ELSE 0
END AS newColumn
FROM TABLEX

or

you can use SUM function

Reply With Quote
  #3  
Old March 8th, 2006, 08:34 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,829 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 5 m 8 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
If you are wanting to concat two fields, then you can use the concat fuction, or the || operator. This only works on character style fields though so if you are working with numeric fields you will have to cast them as char() when passing them into the concat function.

http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db2.doc.sqlref/bjnrmstr215.htm

i.e.
select concat('a','b') from some_table fetch first 1 row only
would return
ab

or

select 'a' || 'b' from some_table fetch first 1 row only
would return
ab

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDB2 Development > Value Gen Formula


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway