I have a table valued function in DB2 which takes AddressCode as one of the parameters. AddressCode is of type Char(50).
When I pass a single string value from my C# code like AddressCode = "ABE001". It works fine, however when i pass in two values
e.g.,
string mAddressCode = "M0044";
string bAddressCode = "B0608";
string formattedAddressCode = mAddressCode + bAddressCode;
I get the following exception
$exception {"ERROR [42601] [IBM][AS] SQL0104N An unexpected token \"MUL0044\" was found following \"\". Expected tokens may include: \") ,\"."} IBM.Data.DB2.Core.DB2Exception
My where clause in Table Valued function looks like this
WHERE A . EMPSFT = 'Y' AND A . EMUKCD in ADDRESScODE
I would like to find out how to format the string to be used for IN Clause in DB2.
The following where clause works
WHERE A . EMPSFT = 'Y' AND A . EMUKCD in ('M0044','B0608')
The SQL script is passed to DB2 like so
string formattedAddressCode = string.Join(",", addressCode.Split(',').Select(x => $"'{x}'"));
string sql = $"SELECT * FROM TABLE ( ABELIBLE.TVFBOEGETSHIPMENTS ( '{formattedStartDate}', '{formattedEndDate}' , '{formattedAddressCode}') )";
sql string looks like this
SELECT * FROM TABLE ( ABELIBLE.TVFBOEGETSHIPMENTS ( '2020-07-06', '2020-08-05' , ''M0044','B0608'') )