kamil hussain
kamil hussain

Reputation: 53

Can we use cfset inside cfquery?

Can we use <cfset> tag inside <cfquery> tag? And how to pass listqualify result to <cfqueryparam> ? Below is my code :

SELECT * FROM EMPLOYEE WHERE _id in (#listqualify(idList,"'")# 

Here idList is supplied by another data source. I want to use on above code to make sure that input is properly provided. I have tried below code but not sure whether i am going on right way or not.

SELECT * FROM EMPLOYEE
WHERE _id in (<cfset idList=#listqualify(idList,"'")#><cfqueryparam value="#idList">) 

Please help me.

Upvotes: 1

Views: 538

Answers (1)

Tushar Bhaware
Tushar Bhaware

Reputation: 2525

Yes. You can use <cfset> tag inside another tag like below:

<cffunction ....>
<cfset x = 'a'>
</cffunction>
OR
    <cfquery ...>
      <cfset x ='a'>
    </cfquery>

The way you are doing is not aesthetically pleasing, you can do it as follows:

<cfset idList = listQualify(idList,"'")>
SELECT * FROM EMPLOYEE WHERE _id in 
(<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#idList#" list="yes">)

Upvotes: 8

Related Questions