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

ColdFusion ORM

New Here ,
Apr 19, 2013 Apr 19, 2013

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

Views

1.2K

Translate

Translate

Report

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

Copy link to clipboard

Copied

Try this:

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

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

V/r,

^ _ ^

Votes

Translate

Translate

Report

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
Documentation