Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1428
  • Last Modified:

DB2 SQL Syntax

I get the following error message when I try to run the query below:

ODBC - Call Failed.

[IBM][CLI Driver][DB2] SQL0420N Invalid character found in a character string argument of the function "n + e". SQL State = 22018 (#-420)

Can anyone tell me what's wrong with the WHERE clause in the query below. Without the where clause, the query works perfectly.
SELECT CInt(Replace(T162_CGY_SHT_NME,'DC','')) AS [Facility Number], IIf(T627_FRG_TER_CD=5 Or T627_FRG_TER_CD=6,'Import','Domestic') AS [Current Sourcing], IIf((T627_FRG_TER_CD=5 Or T627_FRG_TER_CD=6) And T1085_CAC_MTH_ID<>'O','Y','N') AS [Current Import with OTR Freight], IIf([Facility Number] IN (955,960,961,962,965,966,990,992,1419,1420,1421,1436,1440,1449),'RDC',IIf([Facility Number]=964,'Trap',IIf([Facility Number] IN (1438,1439,1446),'Transload','Store'))) AS [Current Flow Path], IIf(T605_RP_TYP_ID='OXD',IIf(OXD_SWT_1XD_IDC='Y','1XD','Stock'),T605_RP_TYP_ID) AS [Current RDC Flow Type], IIf(T627_FRG_TER_CD In (1,4,5),'Collect','Prepaid') AS [Current Freight Terms], IIf([Current Sourcing]='Import', IIf([Current Primary Constraint Type]='Cube', IIf([Current Primary Max Constraint]>=2732,'45''',IIf([Current Primary Max Constraint]>=2362,'40HC''',IIf([Current Primary Max Constraint]>=2081,'40''',IIf([Current Primary Max Constraint]>=1025,'20''','N/A')))),IIf([Current Secondary Constraint Type]='Cube', IIf([Current Secondary Max Constraint]>=2732,'45''',IIf([Current Secondary Max Constraint]>=2362,'40HC''',IIf([Current Secondary Max Constraint]>=2081,'40''',IIf([Current Secondary Max Constraint]>=1025,'20''','N/A')))),'N/A')),'N/A') AS [Current Container Size], IIf(([Current Primary Constraint Type]='Weight' And [Current Primary Max Constraint]>44000) Or ([Current Secondary Constraint Type]='Weight' And [Current Secondary Max Constraint]>44000),'Y','N') AS [Current Heavy Weight Container], IIf([Current Sourcing]='Import',  IIf([T616_CDN_VBU_NBR]>0,'Yes','No'), 'N/A') AS [Current Oversea Consolidation], DES_TXT AS [Current Freight Type], IIf(IFM_PRM_NBR Is Not Null,IFM_PRM_NBR,IFM_PRM_NBR) AS [Current Start Gate DOS], 0 AS [Current Min Gate], IFM_SRCHFLAG_TXT AS [Current TL Searching], IIf(IFM_HDFLAGTAB_1TXT='V','Cube',IIf(IFM_HDFLAGTAB_1TXT='C','Cost',IIf(IFM_HDFLAGTAB_1TXT='W','Weight',IIf(IFM_HDFLAGTAB_1TXT='K','Cases',IIf(IFM_HDFLAGTAB_1TXT='O','Points',IIf(IFM_HDFLAGTAB_1TXT
='P','Pallets',IIf(IFM_HDFLAGTAB_1TXT='U','Units','Other'))))))) AS [Current Primary Constraint Type], IFM_VRMIN_1_NBR AS [Current Primary Min Constraint], IFM_VRMAX_1_NBR AS [Current Primary Max Constraint],IIf(IFM_HDFLAGTAB_2TXT='V','Cube', IIf(IFM_HDFLAGTAB_2TXT='C','Cost',IIf(IFM_HDFLAGTAB_2TXT='W','Weight',IIf(IFM_HDFLAGTAB_2TXT='K','Cases', IIf(IFM_HDFLAGTAB_2TXT='O','Points',IIf(IFM_HDFLAGTAB_2TXT='P','Pallets',IIf(IFM_HDFLAGTAB_2TXT='U','Units','Other'))))))) AS [Current Secondary Constraint Type], IFM_VRMIN_2_NBR AS [Current Secondary Min Constraint], IFM_VRMAX_2_NBR AS [Current Secondary Max Constraint], 1 AS [Current PO Count Per Order Cycle] FROM qryPassThrough
WHERE INT(REPLACE(LOWES.T572_SHP_LCT_GRP.T162_CGY_SHT_NME,'DC','')) IN (955,960,961,962,965,966,990,992,1419,1420,1421,1436,1440,1449,964,1438,1439,1446)

Open in new window

0
ltdanp22
Asked:
ltdanp22
  • 7
  • 6
  • 4
  • +2
3 Solutions
 
Dave FordSoftware Developer / Database AdministratorCommented:

There's probably some non-numeric data in LOWES.T572_SHP_LCT_GRP.T162_CGY_SHT_NME.
0
 
Dave FordSoftware Developer / Database AdministratorCommented:

Look at the data to determine where the bad data is ...


select REPLACE(LOWES.T572_SHP_LCT_GRP.T162_CGY_SHT_NME,'DC','')) 
from   qryPassThrough

Open in new window

0
 
momi_sabagCommented:
would be easier to try

select *
from   qryPassThrough
where trim(translate(REPLACE(LOWES.T572_SHP_LCT_GRP.T162_CGY_SHT_NME,'DC','')),'          ','0123456789','') ) <> ''
0
Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

 
Kent OlsenData Warehouse Architect / DBACommented:
That has got to be the ugliest query that I've ever seen.

Still, most everyone here is on the same theme.

Instead of converting the value to an INT in the filter, quote the items in the IN() list.

WHERE REPLACE(LOWES.T572_SHP_LCT_GRP.T162_CGY_SHT_NME,'DC','') IN ('955','960','961','962','965','966','990','992','1419','1420','1421','1436','1440','1449','964','1438','1439','1446')

Your filter will test every row, even those that don't contain 'DC'.  It may be that you only want to test the rows with 'DC', but your filter doesn't do that.


And of course, if there's a real data issue, Momi's last response shows you how to find the row(s) that don't conform to your expectation.


Good Luck,
Kent
0
 
Kent OlsenData Warehouse Architect / DBACommented:

By the way, that's not DB2 SQL.  It's SQL Server.


But it looks like we've got it covered.  :)


Kent



0
 
aikimarkCommented:
I think the IN() comparisons will be much faster if they remain a list of numeric values.

Likely cause of the error message:
The Replace() function returns a string and needs to be converted to a numeric value.
WHERE CLNG(REPLACE(LOWES.T572_SHP_LCT_GRP.T162_CGY_SHT_NME,'DC','')) IN (955,960,961,962,965,966,990,992,1419,1420,1421,1436,1440,1449,964,1438,1439,1446)

Open in new window

0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi aikimark,

The CLNG function converts a string to a long.  It looks like REPLACE is returning a non-numeric string somewhere in the process.


Kent
0
 
ltdanp22Author Commented:
That worked! There's actually a second half to the WHERE clause that I thought was fine but is still causing problems. Any idea what's wrong here?
WHERE REPLACE(LOWES.T572_SHP_LCT_GRP.T162_CGY_SHT_NME,'DC','') IN ('955','960','961','962','965','966','990','992','1419','1420','1421','1436','1440','1449','964','1438','1439','1446') AND LOWES.T556_RP_MP_VBU.T554_RP_NBR=72370 AND LOWES.T556_RP_MP_VBU.T619_MP_NBR=4 AND LOWES.T556_RP_MP_VBU.T616_VBU_NBR=95001 AND LOWES.T748_EFC_HDR_PRM.IFM_PRM_TXT='G';

Open in new window

0
 
aikimarkCommented:
@Kent

If the output of the Replace() function might not be numeric, convertible into a numeric value, then the VAL() function would work in place of the CLNG().
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi ltdan,

The new filter looks reasonable.  What are you seeing that's wrong?


Kent
0
 
ltdanp22Author Commented:
If I remove all criteria and add any ONE of the following:
LOWES.T556_RP_MP_VBU.T554_RP_NBR=72370
LOWES.T556_RP_MP_VBU.T619_MP_NBR=4
LOWES.T556_RP_MP_VBU.T616_VBU_NBR=95001
I get the same error message as in the OP. The other two criteria do not cause the error. I've checked the data types of the fields referenced and they are all Long Integer.
0
 
aikimarkCommented:
try the following conditions (without table name qualifier)
T554_RP_NBR=72370
T619_MP_NBR=4
T616_VBU_NBR=95001

Open in new window

0
 
Kent OlsenData Warehouse Architect / DBACommented:
The filter looks fine.  Adding any of those 3 lines causes a data conversion exception it's reasonable to assume the data type is not numeric.

0
 
ltdanp22Author Commented:
When I try other numbers in the criteria, the results are returned as expected. It's just 72370, 4, and 95001 that cause the error.
[IBM][CLI Driver][DB2] SQL0420N Invalid character found in a character string argument of the function "n + e". SQL State = 22018 (#-420)
Does that shed any light on the source of the error? Also, does anyone know why the error says the the argument is a string?
0
 
ltdanp22Author Commented:
aikimark,
i tried your suggestion and got an error telling me that the field name was not valid in context.
0
 
Kent OlsenData Warehouse Architect / DBACommented:

Try this:

  SELECT T554_RP_NBR
  FROM QryPassThrough
  WHERE T554_RP_NBR like '%72370%'


That will show you all of the rows with the troublesome value.  It should be easy to identify the offending row(s).


Kent


0
 
ltdanp22Author Commented:
Kent, it didn't like %. Exact error message was an unexpected token '%' was found following ''
0
 
aikimarkCommented:
@ltdanp22

Is this a VB6 application?
Are you going directly to the DB2 database or through an MS-Access database?
 
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi ltdan,

Let me make sure that I understand.  If you run the query with this filter:

WHERE REPLACE(LOWES.T572_SHP_LCT_GRP.T162_CGY_SHT_NME,'DC','')
        IN ('955','960','961','962','965','966','990','992','1419','1420','1421','1436','1440','1449','964','1438','1439','1446')

It works, but when you add the additional filter clauses:

WHERE REPLACE(LOWES.T572_SHP_LCT_GRP.T162_CGY_SHT_NME,'DC','')
        IN ('955','960','961','962','965','966','990','992','1419','1420','1421','1436','1440','1449','964','1438','1439','1446')
  AND LOWES.T556_RP_MP_VBU.T554_RP_NBR=72370
  AND LOWES.T556_RP_MP_VBU.T619_MP_NBR=4
  AND LOWES.T556_RP_MP_VBU.T616_VBU_NBR=95001
  AND LOWES.T748_EFC_HDR_PRM.IFM_PRM_TXT='G';



It fails?  If the three columns in the filter that end with 'NBR' are numeric, that just can't be.


Kent

0
 
ltdanp22Author Commented:
This ended up being a data issue after all (not being able to convert CGY_SHT_NME to a number). I spread the points around since everyone said that this was the problem in varying levels of detail.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 6
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now