Copy link to clipboard
Copied
I have query which should filter the where clause condition depends on the URL parameter to the page?
With CFQuery:
<cfquery name="GetUser" datasource="Sample">
Select *from Users
where <cfif url.type EQ 1>userid=123<cfelse>userid=456</cfif>
</cfquery>
the same query i am tryinng to write with ORMExecuteQuery, i am failing to write it.
Please help me on this.
Thanks in advance
Copy link to clipboard
Copied
Try this:
ORMExecuteQuery("from users where (#url.type# = 1 and userId = 123) or (#url.type# <> 1 and userid=456)")
Copy link to clipboard
Copied
Sorry Ashis, this is not the logic what i am trying...
I need if condition to add the condition to query as i mentioned in the cfquery tag above.
Copy link to clipboard
Copied
Hi Sateesh,
I'd do that like this:
```
<cfscript>
hql = "SELECT * FROM Users WHERE userid = :userid";
params = { "userid" = 456 };
if ( url.type == 1 ) {
params.userid = 123;
}
result = ORMExecuteQuery( hql, params );
</cfscript>
```
Mingo.
Copy link to clipboard
Copied
Might be a bit late to the game, the original was over 4 years ago!
Copy link to clipboard
Copied
It might come in handy for someone else, tho.. just sayin'. 🙂
V/r,
^ _ ^