Link to home
Start Free TrialLog in
Avatar of traport
traport

asked on

SQL query of a ColdFusion List

I have a query and I'm trying to see if one of the SQL variables is LIKE one of the items in a list. At the end of the query I have

  AND tblPerson_RTIDetail.personUnit IN (#PreserveSingleQuotes(session.userRoleUnits)#)

This appears to be doing only a direct match. Can I use "LIKE" in place of "IN" and, if so, how would I place the %?

Thanks a lot!
SOLUTION
Avatar of nmarano
nmarano

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of _agx_
Can I use "LIKE" in place of "IN"

If #session.userRoleUnits# contains multiple values - then NO.  What you could do is loop through the list and generate a LIKE statement for each one as @nmarano described above

WHERE  .....
<cfloop list="#session.userRoleUnits#" index="unit">
    AND tblPerson_RTIDetail.personUnit LIKE '#unit#%'
</cfloop>

#PreserveSingleQuotes(session.userRoleUnits)#

( I've probably mentioned it before, but that's a very dangerous function to use on sql server )
Avatar of traport
traport

ASKER

Yes it will have multiple values.

Why is it a dangerous function? Thanks for bringing it to my attention.

I'll go try this now.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial