crystal reports : splitting delimited field to columns - crystal-reports

How do I split a delimited field into columns in Crystal Reports XI?
The data in the fields looks like this:
value1 \t value2 \t value3 \r\n
value1 \t value2 \t value3 \r\n
I would like to format it as
Value1 Value2 Value3
I tried putting the fields into Crystal but the tab delimiters are not formatting correctly.
It displays as:
Value1 Value2Value3
Thanks in advance.

You will need three formulas:
//{#one}
Split({table.field}, " \t")[1];
//{#two}
Split({table.field}, " \t")[2];
//{#three}
Split(Split({table.field}, " \t")[3], " ")[1];

This works for Cyrstal Reports 2013 edition as well. I have a column which was separated by ',' and creating multiple formulas worked. Thank you #craig :)
Split({table.field}, ",")[1];

Related

Abap: Select the same field from two db tables into one column of the internal table with one select

I'm new in using SQL in ABAP, so it must be a silly question, but is this somehow possible?:
as I'm new, I cannot add images directly.
Thanks a lot in advance, kind regards
It appears that what you want to do is create an SQL "Union": Select rows from two different database tables and put the results into one combined table. This is only possible if both SELECTs have the same fields. But you can usually accomplish that pretty easily by substituting the missing rows in each table by a constant value ('' in this example):
SELECT
key1
'' as key2
value1
value2
value3
'' as value4
FROM db1
UNION SELECT
key1
key2
value1
'' as value2
'' as value3
value4
FROM db2
INTO CORRESPONDING FIELDS OF TABLE #it.
When you are using an older release (<7.50), then you can combine the data of multiple SELECTs by using APPENDING instead of INTO:
SELECT
key1
value1
value2
value3
FROM db1
INTO CORRESPONDING FIELDS OF TABLE #it.
SELECT
key1
key2
value1
value4
FROM db2
APPENDING CORRESPONDING FIELDS OF TABLE #it.

Concatenate a column from multiple rows into a single formatted string

I have rows like so:
roll_no
---------
0690543
0005331
0760745
0005271
And I want string like this :
"0690543.pdf" "0005331.pdf" "0760745.pdf" "0005271.pdf"
I have tried concat but unable to do so
You can use an aggregate function like string_agg, after first mangling the quotes and the .pdf extension to your column data. Use a space as your delimiter:
SELECT string_agg('"'||roll_no||'.pdf "', ' ') from myTable
SqlFiddle here

Get substring into a new column

I have a table that contains a column that has data in the following format - lets call the column "title" and the table "s"
title
ab.123
ab.321
cde.456
cde.654
fghi.789
fghi.987
I am trying to get a unique list of the characters that come before the "." so that i end up with this:
ab
cde
fghi
I have tried selecting the initial column into a table then trying to do an update to create a new column that is the position of the dot using "ss".
something like this:
t: select title from s
update thedot: (title ss `.)[0] from t
i was then going to try and do a 3rd column that would be "N" number of characters from "title" where N is the value stored in "thedot" column.
All i get when i try the update is a "type" error.
Any ideas? I am very new to kdb so no doubt doing something simple in a very silly way.
the reason why you get the type error is because ss only works on string type, not symbol. Plus ss is not vector based function so you need to combine it with each '.
q)update thedot:string[title] ss' "." from t
title thedot
---------------
ab.123 2
ab.321 2
cde.456 3
cde.654 3
fghi.789 4
There are a few ways to solve your problem:
q)select distinct(`$"." vs' string title)[;0] from t
x
----
ab
cde
fghi
q)select distinct(` vs' title)[;0] from t
x
----
ab
cde
fghi
You can read here for more info: http://code.kx.com/q/ref/casting/#vs
An alternative is to make use of the 0: operator, to parse around the "." delimiter. This operator is especially useful if you have a fixed number of 'columns' like in a csv file. In this case where there is a fixed number of columns and we only want the first, a list of distinct characters before the "." can be returned with:
exec distinct raze("S ";".")0:string title from t
`ab`cde`fghi
OR:
distinct raze("S ";".")0:string t`title
`ab`cde`fghi
Where "S " defines the types of each column and "." is the record delimiter. For records with differing number of columns it would be better to use the vs operator.
A variation of WooiKent's answer using each-right (/:) :
q)exec distinct (` vs/:x)[;0] from t
`ab`cde`fghi

Getting the values in between

In Report Builder 3.0 I have a string of comma separated values e.g. "Value1, Value2, Value3, Value4". I have used Split() to get the first and the last position but how do I get everything that is in between "Value1" and "Value4". Can I remove the first and last position in the array that the split function creates? The result i am looking for is "Value2, Value3".
I can think of a couple of methods:
=Trim(Split(Fields!valueString.Value, ",")(1))
& ", "
& Trim(Split(Fields!valueString.Value, ",")(2))
Similar to what you're already doing, just concatenates the two values back together. Trim just helps avoid any issues with whitespace.
=Trim(Mid(Fields!valueString.Value
, InStr(Fields!valueString.Value, ",") + 1
, InStrRev(Fields!valueString.Value, ",") - InStr(Fields!valueString.Value, ",") - 1))
This just uses string manipulation based on comma positions. Again Trim is used to clean up whitespace.
Neither of these are necessarily perfect when your input string is an unexpected format, so depending on your data extra checks might be required, but for Value1, Value2, Value3, Value4 both expressions return Value2, Value3 as required.

crystal report export to excel in 1 horizontal line of all data rows

I have a report which has ONLY "Report header" section and NO "Detail section", NO any other sections.
It should be in that format cause I have a query which returns 1 row with many columns, like this:
val1, val2, val3, val4, val5, val6
And I want it to display in crystal report and in excel file like this:
constant Label1 val1
constant Label2 val2
constant Label3 val3
constant Label4 val4
constant Label5 val5
constant Label6 val6
It displays correctly in crystal report but when export to excel (data only), it takes all of these into 1 horizontal line with multiple columns:
constant Label 1 val1 constant Label 2 val2 constant Label 3 val3.....
How to solve this? Thanks so much!!!
The reason the export is throwing all the values onto one line in Excel is because there are no delimiters that excel can understand. Just putting them one value above the other in the same section in the report isn't enough. There are a few things you can try.
If you only have 6 rows, just break up the Report Header into 6 subsections and into each subsection put a constant-Label-value. CR will probably export these with some sort of delimiter that will carry over to Excel.
If that doesn't work, put one formula in the Report Header that builds up one long string of values that you want using tabs, newlines, whatever. For example, totext(constant) + chr(9) + label + chr(10) + totext(constant2) + ... Or however you want the data formatted. The downside to this method is that you'll lose the format for each cell (rather, all cells will be string types).