Wild Character Help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to use a wild character in the LIKE part of my select statement
for connecting to an AS400 database table and can't get it to work properly.
I can get it to work when I hard code the value in. See below...

strSelectStr = New IBM.Data.DB2.iSeries.iDB2Command("select * from
LIBRARY.CKTIMEFLK5 where TICONO=1 and TIEMPN= 1710 and TIRTIM
LIKE '20070207%'", cn)

However when I try to use a variable that is holding the value I can't get
it to work properly. Below is one of the methods I tried, however it doesn't
match a record and I know that 20070207 is the value of intCardDate.

strSelectStr = New IBM.Data.DB2.iSeries.iDB2Command("select * from
KITDATA.CKTIMEFLK5 where TICONO=1 and TIEMPN= 1710 and TIRTIM LIKE '" &
"'" & intCardDate & "'%'" & "'" & "'", cn)

Can anyone help me out with how I should properly code my LIKE statement.
Thanks in advance.
 
strSelectStr = New IBM.Data.DB2.iSeries.iDB2Command("select * from
KITDATA.CKTIMEFLK5 where TICONO=1 and TIEMPN= 1710 and TIRTIM LIKE '" &
"'" & intCardDate & "'%'" & "'" & "'", cn)

Can anyone help me out with how I should properly code my LIKE statement.
Thanks in advance.

If I'm not mistaken, it looks like you have an extra apostrophe around
the intCardDate value. To make sure you should try setting a variable
and using string.format like so:

dim sQuery as String = String.Format("Select * From KITDATA.CKTIMEFLK5
Where TICONO=1 and TIEMPN = 1710 and TIRTIM Like '{0}%'",intCardDate)

Then set the Command's CommandText to squery. If that doesn't work
then I'd break in the debugger and copy the value out for sQuery and
try running it manually against the data source to verify your syntax.
 
Back
Top