I am trying to get the contents of a list enclosed with single quotes around each item. I have been using the list qualify and it seems to work to get the list correctly formatted but when I use the list in a query it comes out wrong. I will put the code below and the erro I am getting.
error:
ODBC Error Code = 37000 (Syntax error or access violation)
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 3: Incorrect syntax near 'TEST2'.
SQL = "SELECT ProductId_pk, ProductId_fk, NIN, ProductName FROM tblProducts INNER JOIN tblPackages ON ProductId_fk = ProductId_pk WHERE (tblProducts.ProductName in (''TEST2'',''Test1''))"
If I output the qualifiedlist it shows the list with one set of single quotes around each item.
notice it seems sql is putting its own set of single quotes around each item and that is the reason I am getting the error. Any ideas on what is going on and why?
Code:
<CFSET qualifiedList=ListQualify(#strProductNames#,"'")>
<cfoutput>
<cfquery name="getIDs" datasource="#dbms#">
SELECT ProductId_pk, ProductId_fk, NIN, ProductName
FROM tblProducts INNER JOIN tblPackages ON ProductId_fk = ProductId_pk
WHERE (tblProducts.ProductName in (#qualifiedList#))
</cfquery>
</cfoutput>
error:
ODBC Error Code = 37000 (Syntax error or access violation)
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 3: Incorrect syntax near 'TEST2'.
SQL = "SELECT ProductId_pk, ProductId_fk, NIN, ProductName FROM tblProducts INNER JOIN tblPackages ON ProductId_fk = ProductId_pk WHERE (tblProducts.ProductName in (''TEST2'',''Test1''))"
If I output the qualifiedlist it shows the list with one set of single quotes around each item.
notice it seems sql is putting its own set of single quotes around each item and that is the reason I am getting the error. Any ideas on what is going on and why?