Skip to main content
Participant
April 19, 2013
Question

ColdFusion ORM

  • April 19, 2013
  • 2 replies
  • 1350 views

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

This topic has been closed for replies.

2 replies

Participant
October 18, 2017

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.

Inspiring
October 18, 2017

Might be a bit late to the game, the original was over 4 years ago!

WolfShade
Legend
October 18, 2017

It might come in handy for someone else, tho..  just sayin'.  :)

V/r,

^ _ ^

Inspiring
April 19, 2013

Try this:

ORMExecuteQuery("from users where (#url.type# = 1 and userId = 123) or (#url.type# <> 1 and userid=456)")

SateeshAuthor
Participant
April 19, 2013

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.