Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

ColdFusion ORM

New Here ,
Apr 19, 2013 Apr 19, 2013

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

1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 19, 2013 Apr 19, 2013

Try this:

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 19, 2013 Apr 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 18, 2017 Oct 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 18, 2017 Oct 18, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 18, 2017 Oct 18, 2017
LATEST

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

V/r,

^ _ ^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources