r17 Posted April 26, 2010 Share Posted April 26, 2010 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 More sharing options...
slow Posted April 26, 2010 Share Posted April 26, 2010 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 More sharing options...
r17 Posted April 26, 2010 Author Share Posted April 26, 2010 is there a way in which i can do in SQL? Link to comment Share on other sites More sharing options...
slow Posted April 26, 2010 Share Posted April 26, 2010 string functions are not SQL standard... so you're talking abot SQL for ORACLE, mySQL, Hypersonic... what? Link to comment Share on other sites More sharing options...
r17 Posted April 26, 2010 Author Share Posted April 26, 2010 im actually trying to transfer from mysql into sql in ireport. Link to comment Share on other sites More sharing options...
slow Posted April 26, 2010 Share Posted April 26, 2010 in mySql... try something like this:SELECT ....... , CHAR_LENGTH(REPLACE( yourField , '0', '')) as lengthFROM ..... ____________________________________if it works... give me KARMA points please! : ) Link to comment Share on other sites More sharing options...
r17 Posted April 26, 2010 Author Share Posted April 26, 2010 hi slow, thanks for helping me but your answer doesnt apply to mine.i wanna add up all the 1 together.. is there a function to do so? like sum ( substring )????????????????? Link to comment Share on other sites More sharing options...
slow Posted April 26, 2010 Share Posted April 26, 2010 if your substring is in the format "011100101001"thenSELECT CHAR_LENGTH(REPLACE( substring , '0', '')) as lengthFROM aTablereturn 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 More sharing options...
r17 Posted April 27, 2010 Author Share Posted April 27, 2010 this is my sql statmentSELECT*, campaignmonth, substring(campaignmonth,1,1)as JanFrom 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 More sharing options...
r17 Posted April 27, 2010 Author Share Posted April 27, 2010 Alright, i solved it. thanks ! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now