Jump to content

adding substring


r17

Recommended Posts

hello,

i have a table of data filled with 1 and 0  with the help of substring.

 

Jan Feb Mar Apr May June July Aug Sept Oct Nov Dec Total
1 0 1 1 1 1 1 0 1 0 1 1 ?????

 

is there a way in which i am able to add up all the 1 (formed by substring) ??

Thanks :D

Link to comment
Share on other sites

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

you can do it with java...
it's a fun trick:

suppose $F{TEXT} contains your string...

then you can print the "1" count with a textfield (Integer type)

new Integer($F{TEXT}.replaceAll("[^1]","")).length())

 

 

____________________________________
if it works... give me KARMA points please!    : ) 

Link to comment
Share on other sites

if your substring is in the format "011100101001"

then

SELECT  CHAR_LENGTH(REPLACE( substring , '0', '')) as length
FROM aTable

return the sum you want... 6!

 

is the substring you talk about in a different format?

 

____________________________________
if it works... give me KARMA points please!    : ) 



Post Edited by slow at 04/26/2010 14:47
Link to comment
Share on other sites

this is my sql statment

SELECT*,
campaignmonth, substring(campaignmonth,1,1)as Jan

From campaign;

I'd like to sum up all the substring information as shown in the table above. is there a way to do so?

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...