Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

chris1987
Contributor

SQL Load from Database incorrect data - Appending leading zero

Hi,

I've hit a big problem that I can't figure out.

I have a table that I am doing an SQL Query on. Really, really simple.

The script I am using is:

TempItem:
SQL SELECT 
"Item-no",
"Full-Description"
FROM UKTABLE.PUB."item";

The field I am interested in is the "Item-no", this contains some item numbers with leading zero's and some without.

For example:

Item-No   |   Full-Description
------------------------------------------------------- 38033 | Part 1 038033 | Sub-Assembly 1

As you can see there are two part numbers.

But when I run the above code and put the fields in a table, I get the following:

Item-No | Full-Description
-------------------------------------------------------
038033 | Part 1
038033 | Sub-Assembly 1

*Note that Part 1 now has a zero at the front.

This is incorrect and is skewing my figures.

I know that QV stores the value as double, but I've tried this too with no success:

TempItem: 
SQL 
SELECT CAST("Item-no" as varchar(20)) AS "Item-no",
"Full-Description"
FROM UKTABLE.PUB."item";

And I've also saved the data to a .qvd and loaded it with the following, again with no success:

TempItem:
LOAD text([Item-no]) as [Item-no], 
Full-Description
FROM
[D:\Qlikview\UK\Data\Item.qvd](qvd);

Here is my SQL Database table, as you can see it's already in text format

Capture.JPG

Has anyone come across this before?

Cheers

Chris

Labels (2)
1 Solution

Accepted Solutions
MVP & Luminary
MVP & Luminary

Re: SQL Load from Database incorrect data - Appending leading zero

Try it in this way:

TempItem:
load text("Item-no") as "Item-no", "Full-Description";
SQL SELECT "Item-no", "Full-Description"
FROM UKTABLE.PUB."item";

- Marcus

View solution in original post

3 Replies
MVP & Luminary
MVP & Luminary

Re: SQL Load from Database incorrect data - Appending leading zero

Try it in this way:

TempItem:
load text("Item-no") as "Item-no", "Full-Description";
SQL SELECT "Item-no", "Full-Description"
FROM UKTABLE.PUB."item";

- Marcus

View solution in original post

chris1987
Contributor

Re: SQL Load from Database incorrect data - Appending leading zero

Thanks Marcus,

I've only done a small sample test and it appears to be working! So just running it on the full db now.

Do you know why this works? Would be good if you could explain a little or point me in the direction of an answer. Will be good to know in future.

Cheers

Chris

Highlighted
MVP & Luminary
MVP & Luminary

Re: SQL Load from Database incorrect data - Appending leading zero

The reason for this behaviour is that Qlik doesn't really know data-types else it interprets the data as numeric or strings - and this happens by the first loaded field-value and is then applied to the whole column. With the most of the columns it worked very smoothly and only by such cases with a leading zero or similar stuff you need to enforce a different handling which is usually done with a text().

- Marcus