Len function not working (1 Viewer)

S_Preston

Registered User.
Local time
Today, 10:42
Joined
Jan 8, 2018
Messages
18
Hello,

I have a short text field called [license] in a table that is set to 13 characters; the total number of records in this table is 323,992. I wish to capture only data in [license] where the data in this field is equal to 13 characters. I have 5932 records where the value is listed as 0. I have an unknown number of records where the value is less than 13 characters. I have attempted to create group by query where Len([license]) query where the criteria is 13 and License is displayed, that returned the same number 303,979 records. This query did not produce favorable results I can clearly see the License string has less than 13 characters. Does anyone have any suggestions? I realize that I can manipulate the data in Excel Len function but I cannot export 323,992 records at once into Excel. :banghead:
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 11:42
Joined
Apr 27, 2015
Messages
6,345
In the query grid, try Len([liscense]) = 13

I cannot test it becuase I am not at my computer, but I THINK it will work.
 

MarkK

bit cruncher
Local time
Today, 08:42
Joined
Mar 17, 2004
Messages
8,186
What happens if you get really basic, like...
Code:
SELECT Len(YourField) As LengthOfField
FROM YourTable
See how that's a query with a single calculated field showing the length of a single field in the table? That way you can determine if the Len() function is working, and if it is, start adding the features you need to that working query.

Alternatively, if you are having trouble with SQL, post the SQL.

hth
Mark
 

bob fitz

AWF VIP
Local time
Today, 16:42
Joined
May 23, 2011
Messages
4,727
In the query grid, try Len([liscense]) = 13

I cannot test it becuase I am not at my computer, but I THINK it will work.
While you were posting I was testing. Can confirm that
Len([license]) = 13
should indeed work. BTY you have made a slight spelling mistake in the name of the field.
 

S_Preston

Registered User.
Local time
Today, 10:42
Joined
Jan 8, 2018
Messages
18
Markk -

Your query produced results of "13" in all 323,992 fields.
 

jdraw

Super Moderator
Staff member
Local time
Today, 11:42
Joined
Jan 23, 2006
Messages
15,378
Perhaps, based on Markk's post, to see if there is some pattern???

Code:
SELECT YourField,Trim(Yourfield) as Trimmed, Len(YourField) As LengthOfField
FROM YourTable
 

MarkK

bit cruncher
Local time
Today, 08:42
Joined
Mar 17, 2004
Messages
8,186
Markk -
Your query produced results of "13" in all 323,992 fields.
Perfect, that reveals a feature of the problem, so now riffing off jdraw's post...
Code:
SELECT Len(Trim(YourField)) As LengthOfYourFieldTimmed
FROM YourTable
Also, if you show us your actual SQL then as we tweak is, you can just copy and paste it, as an idea.
Mark
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:42
Joined
May 7, 2009
Messages
19,247
Add criteria to License:

Like "[1-9A-Z]????????????"
 

S_Preston

Registered User.
Local time
Today, 10:42
Joined
Jan 8, 2018
Messages
18
NauticalGent, results provided did not provide me with the desired result. The field size is set to 13 characters, and always returns the same number of records 323,992.
 

jdraw

Super Moderator
Staff member
Local time
Today, 11:42
Joined
Jan 23, 2006
Messages
15,378
We need to see some actual SQL.
And some sample data.
 

Mark_

Longboard on the internet
Local time
Today, 08:42
Joined
Sep 12, 2017
Messages
2,111
Can you copy the offending table to its own db, add in the same query you are trying to use, and test there? If it work separately you may have a corruption issue. If it doesn't, you can then zip and post the database to let us help find the issue.
 

S_Preston

Registered User.
Local time
Today, 10:42
Joined
Jan 8, 2018
Messages
18
MarkK, that worked!

SELECT Len(Trim(YourField)) As LengthOfYourFieldTimmed
FROM YourTable
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 11:42
Joined
Apr 27, 2015
Messages
6,345
NauticalGent, results provided did not provide me with the desired result. The field size is set to 13 characters, and always returns the same number of records 323,992.

I have tried this on a few tables of mine and it has ALWAYS worked. Out of curiosity, are you using field masks?
 

Minty

AWF VIP
Local time
Today, 16:42
Joined
Jul 26, 2013
Messages
10,371
This sounds (as NG has asked) as if the data has padding on it to always store as 13 characters.

In SQL server this would be a Char(13) type data and is fixed length and always stores 13 characters, instead of the normally preferred VarChar(13) which will store up to 13 characters.
 

Users who are viewing this thread

Top Bottom