"Overflow" error - string to integer // SQL

PureBluff

Board Regular
Joined
Apr 4, 2014
Messages
174
Office Version
  1. 2016
Platform
  1. Windows
  2. Mobile
Merry Christmas to all at Mr Excel,
Hope you're working as hard as I am over the festive/holiday season :laugh:

Trying to write a few ODBC queries into an old IBM AS/400 / iSeries server. It's all gone well using fixed values, but now I'm trying to add in some variables, it's getting a bit more troublesome!

In short, the dates are stored on the AS400 in the format of YYMMDD, so if I code 28-Dec-17 as

"select clntth, trdtth, trf2th, commth, sdsccd, pal#th, dtcdth, trnqth, srb#th, sri#th, IPALPM, PLTPPM from warhist as T01" & Chr(13) & "" & Chr(10) & "left outer join warpall on warpall.pal#pm = T01.pal#th and warpall.commpm = " _ , _
"t01.commth" & Chr(13) & "" & Chr(10) & "INNER JOIN WARCMDT ON WARCMDT.CLNTCD = T01.CLNTTH and WARCMDT.CommCD = T01.commTH" & Chr(13) & "" & Chr(10) & "" & Chr(13) & "" & Chr(10) & "where clntth = 'D4' and trdtth = 171228 and trncth in (' 31', ' 51', ' 52', ' 53')" _
)

It works fine, yet if I set it as a variable:

dat3 = format(now() - 2, "YYMMDD")

"select clntth, trdtth, trf2th, commth, sdsccd, pal#th, dtcdth, trnqth, srb#th, sri#th, IPALPM, PLTPPM from warhist as T01" & Chr(13) & "" & Chr(10) & "left outer join warpall on warpall.pal#pm = T01.pal#th and warpall.commpm = " _
, _
"t01.commth" & Chr(13) & "" & Chr(10) & "INNER JOIN WARCMDT ON WARCMDT.CLNTCD = T01.CLNTTH and WARCMDT.CommCD = T01.commTH" & Chr(13) & "" & Chr(10) & "" & Chr(13) & "" & Chr(10) & "where clntth = 'D4' and trdtth = dat3 and trncth in (' 31', ' 51', ' 52', ' 53')" _
)

I get an overflow error, so I tried CInt;

Patch = format(now() - 2, "YYMMDD")
dat3 = CInt(patch)

"select clntth, trdtth, trf2th, commth, sdsccd, pal#th, dtcdth, trnqth, srb#th, sri#th, IPALPM, PLTPPM from warhist as T01" & Chr(13) & "" & Chr(10) & "left outer join warpall on warpall.pal#pm = T01.pal#th and warpall.commpm = " _
, _
"t01.commth" & Chr(13) & "" & Chr(10) & "INNER JOIN WARCMDT ON WARCMDT.CLNTCD = T01.CLNTTH and WARCMDT.CommCD = T01.commTH" & Chr(13) & "" & Chr(10) & "" & Chr(13) & "" & Chr(10) & "where clntth = 'D4' and trdtth = dat3 and trncth in (' 31', ' 51', ' 52', ' 53')" _
)

Yet I get an overflow error again - which seems to be related to using a string sa integer or vice-versa.

Anyone able to advise?
Thanks,
Steven
 
Last edited:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I tried CLng too, but I get an error when trying to referesh the query, which suggests the SQL syntax is wrong.

Dat3 shows as 171228 without "" so integer.

Im really at a loss
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top