Link to home
Start Free TrialLog in
Avatar of NickHoward
NickHoward

asked on

how to overcome string at most 65534 characters long

Hi,

I have formula in my CR 2008. It was working okay when there was less data.

However now I get message "a string can be at most 65534 characters long".

Please revise my existig formula to overcome this error.

Formula name: RESULT

stringvar prefix;
stringvar country;
stringvar route;
stringvar Type;
stringvar output;
prefix:={Sheet3_.Access};
country:={Sheet3_.Country} ;
route:= {Sheet3_.Routes};
type:="4";

numbervar x;
numbervar ub;
stringvar array Routes;
routes:=split(route,",");
ub:= ubound(routes);
for x:=1 to ub-1 do

output:= output & "Insert into dbo.s_route_vs_tmp (prefix, country, route, Priority, Type) VALUES('"&Prefix&"',"&"'"&mid(country,1,15)&"',"&"'"&routes[x]&"',"&"'"&totext(x-1,0,"")&"',"&"'0');"& chr(13)& chr(10);

output:= output & "Insert into dbo.s_route_vs_tmp (prefix, country, route, Priority, Type) VALUES('"&Prefix&"',"&"'"&mid(country,1,15)&"',"&"'"&routes[ub]&"',"&"'"&totext(x-1,0,"")&"',"&"'4');"&chr(13)& chr(10);

If you want I can attach report and datasource (in Excel).

Thanks in advance for your help.
Avatar of JayConverse
JayConverse
Flag of United States of America image

You need to have less data.  Or, break it up into multiple stringvars and multiple outputs.
Avatar of NickHoward
NickHoward

ASKER

Data can not be less and may increase.

Can you show how to breakup into multiple outputs?

Thanks.
How are you writing or executing the "output" variable?
In Detail section I put my above formula.

If u want I can attach CR report and excel backend data.
Just the report.
Report attached
test.rpt
I think your basic problem is "when all you have is a hammer, everything looks like a nail".  Crystal may not be the tool for this.  

So, what exactly are you trying to do with this output?  

I wonder if you could make the output variable a string array? Then instead of setting storing the concatenated result in a variable store each iteration in it's own element of the array. Then at the end return the whole array?

L
Well said. Actually I am using CR report to create sql insert.

May bit strange for you, but it was doing the great job unless data was less.

Hope you can look at formula and can suggest multiple outputs.

Thanks.
Yes- you can simply have a SQL statement:

SELECT 'INSERT INTO mytable (field1, field2) VALUES (''' + fielda + ''', ''' + fieldb + ''')' FROM someothertable

You could even do the insert all in one if all you're intending to do is copy/paste the INSERT statements?

L
tickett,

Sorry for not being understood.

Looks like no solution to avoid  65534 long characters for my existing requirement.

Shall I close the question?
But how are you getting from the Crystal report to the SQL statement?  Exporting to a text file?
Yeah into CSV file and running from SQL DTS.
Wow- that seems seriously long winded. I think i may have already answered "this question" about how to get around the error.

I think you need to post a new question with regard to the task you are trying to achieve with this current crystal/dts solution? Some of us experts can probably suggest smarter ways to attack it.

L
Avatar of Mike McCracken
YOu can use an array of strings but the handling would be difficult.

Basic idea
NumberVar StringIndex := 1;
StringVar Array MyStrings[1];

for x:=1 to ub-1 do
If Length(MyStrings[StringIndex]) >= 65000 then
(
    StringIndex := StringIndex + 1;
    ReDim Preserve MyStrings[StringIndex];
)
MyStrings[StringIndex] := MyStrings[StringIndex] & "Insert into dbo.s_route_vs_tmp (prefix, country, route, Priority, Type) VALUES('"&Prefix&"',"&"'"&mid(country,1,15)&"',"&"'"&routes[x]&"',"&"'"&totext(x-1,0,"")&"',"&"'0');"& chr(13)& chr(10);

You would then need separate formulas to print/display each member of the MyStrings array

mlmcc
mlmcc,

Thanks for the tip. I tried to impment but I guess I am doing something wrong.

Can you check my report and suggest complete formula1, formula2 so that I adopt it?

Sorry for being so naive.
If you can upload the report, I will be happy to try and fix it.

You could also just copy and paste the formulas.

mlmcc
Thanks mlmcc. Actually I am fan of yours. You did help me in past.

Formula my report is: "output"

stringvar prefix;
stringvar country;
stringvar route;
stringvar Type;
stringvar output;
prefix:={Sheet3_.Access};
country:={Sheet3_.Country} ;
route:= {Sheet3_.Routes};
type:="4";

numbervar x;
numbervar ub;
stringvar array Routes;
routes:=split(route,",");
ub:= ubound(routes);
for x:=1 to ub-1 do

output:= output & "Insert into dbo.s_route_vs_tmp (prefix, country, route, Priority, Type) VALUES('"&Prefix&"',"&"'"&mid(country,1,15)&"',"&"'"&routes[x]&"',"&"'"&totext(x-1,0,"")&"',"&"'0');"& chr(13)& chr(10);
output:= output & "Insert into dbo.s_route_vs_tmp (prefix, country, route, Priority, Type) VALUES('"&Prefix&"',"&"'"&mid(country,1,15)&"',"&"'"&routes[ub]&"',"&"'"&totext(x-1,0,"")&"',"&"'4');"&chr(13)& chr(10);


I am attaching report with data saved in it.

Let me know if data source (excel file also required).

Thanks.
test.rpt
Check this revision

mlmcc
test1rev.rpt
Hi mlmcc,

I tried your revised report but it was only bringing last record from datasource and was repeating 3 times.

I think using sql statements as output is getting this difficult to solve.

You have helped me in past check:
https://www.experts-exchange.com/questions/25010605/Splitting-into-row-based-on-route.html

I have same thing now but my data grew and therefore getting limitations.

I am attaching new report with data in excel to test it.

Hope it is easier know to look at output.

Thanks in advance.
Prefixes-Routing.xls
test.rpt
Does this report do what you want?

mlmcc
testRev1.rpt
Checking and thanks.
mlmcc,

You almost solved it. Only change required is that for at end of each array, value of Type should be '4' instead of '0'

For instance, select prefix 0032:

Insert into dbo.s_route_vs_tmp (prefix, country, route, Priority, Type) VALUES('0032','Belgium','14','0','0');
Insert into dbo.s_route_vs_tmp (prefix, country, route, Priority, Type) VALUES('0032','Belgium','19','1','0');
Insert into dbo.s_route_vs_tmp (prefix, country, route, Priority, Type) VALUES('0032','Belgium','2','2','0');
Insert into dbo.s_route_vs_tmp (prefix, country, route, Priority, Type) VALUES('0032','Belgium','15','3','0');
Insert into dbo.s_route_vs_tmp (prefix, country, route, Priority, Type) VALUES('0032','Belgium','4','4','0');
Insert into dbo.s_route_vs_tmp (prefix, country, route, Priority, Type) VALUES('0032','Belgium','13','5','0');
Insert into dbo.s_route_vs_tmp (prefix, country, route, Priority, Type) VALUES('0032','Belgium','6','6','0');
Insert into dbo.s_route_vs_tmp (prefix, country, route, Priority, Type) VALUES('0032','Belgium','17','7','0');
Insert into dbo.s_route_vs_tmp (prefix, country, route, Priority, Type) VALUES('0032','Belgium','22','8','4');

You can see that for each prefix last entry ends with type '4'.
I tried to achieve it by modifying output formula but no luck.
Thanks and already grateful for your assistance.


ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
mlmcc ROCKS !!!

This solved the issue.

I wish I can raise points from 500 to 1000.

Bundle of thanks for this help,
No match with mlmcc. When no one there to help, mlmcc steps in and solve most difficulet tasks. God Bless.
Thanks for the kind words.  

mlmcc