Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
haymarketpaul
Creator III
Creator III

Determine Longest Field Size

Morning All

Qlikview 12 SR5

I've got a csv file with about 300 fields in it and approx 1 million rows.

For each field I need to work out the maximum size/length of the data in it.

Here's a simple example...

Field1Field2
PaulRed
HarryBlue
RobertGreen
DaveGrey
DanPink

 

So looking at the above Field1 would be 6 (Robert) and Field2 would be 5 (Green)

So I just need to list of the max size of these 300 fields

Field16
Field25

etc

I ultimately need to create some SQL Server tables for this data so want to use this info to determine field sizes in that

Labels (2)
1 Solution

Accepted Solutions
marcus_sommer
MVP
MVP

I think I would do something like this:

csv: load * from csv.csv;

for i = 1 to nooffields('csv')
   let f = fieldname($(i), 'csv');
   t: load '$(f)' as Field, max(len(fieldvalue('$(f)', recno()))) as MaxLenght
       autogenerate fieldvaluecount('$(f)');
next

- Marcus

View solution in original post

3 Replies
Frank_Hartmann
Master II
Master II

Maybe like this?

tmp:
Load * Inline [
Field1,	Field2
Paul,	Red
Harry,	Blue
Robert,	Green
Dave,	Grey
Dan,	Pink
];

left join

Load max(len(Field1)) as Max1, max(len(Field2)) as Max2 Resident tmp;
marcus_sommer
MVP
MVP

I think I would do something like this:

csv: load * from csv.csv;

for i = 1 to nooffields('csv')
   let f = fieldname($(i), 'csv');
   t: load '$(f)' as Field, max(len(fieldvalue('$(f)', recno()))) as MaxLenght
       autogenerate fieldvaluecount('$(f)');
next

- Marcus

haymarketpaul
Creator III
Creator III
Author

Brilliant - thank you

and wow 212 chars in the postcode field - someone must live somewhere odd 🙂