Question
Problem with IN clause
I thought the concept was straight forward but I cannot
figure out how to write the code for a table where one field,
Category, may have several values. Category is set as an nvarchar
field and typical data in this field may be 2,3,8. Here is the code
I have written that does not work. The user starts at an index page
and selects a category by name which is then converted to the
category number and added to the URL after the ?, i.e. <a
href="Products/Overview1.cfm?CatNum=#CatNum#">#Category#</a>
Before I realized that some products would fall into more than one category, everything worked fine. Now I am trying to avoid having to duplicate a row with only the category being different. Thought it was easy but now I am really frustrated. Anyone able to help?
<CFIF ParameterExists(URL.CatNum)>
<cfquery name="GetProductOverview" datasource="#DS#" username="#User#" password="#PW#">
SELECT ProdID, ProdName, ImageFileName, ImageHeight, ImageWidth, Category, Active
FROM Products
WHERE Active = 'true'
AND Category IN '#URL.CatNum#'
ORDER BY CatalogNum asc
</cfquery>
<cfelse>
<cflocation url="../index.cfm">
</CFIF>
Thanks,
Warren
Before I realized that some products would fall into more than one category, everything worked fine. Now I am trying to avoid having to duplicate a row with only the category being different. Thought it was easy but now I am really frustrated. Anyone able to help?
<CFIF ParameterExists(URL.CatNum)>
<cfquery name="GetProductOverview" datasource="#DS#" username="#User#" password="#PW#">
SELECT ProdID, ProdName, ImageFileName, ImageHeight, ImageWidth, Category, Active
FROM Products
WHERE Active = 'true'
AND Category IN '#URL.CatNum#'
ORDER BY CatalogNum asc
</cfquery>
<cfelse>
<cflocation url="../index.cfm">
</CFIF>
Thanks,
Warren