Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6893559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:40:25+00:00 2026-05-27T06:40:25+00:00

I have the following query: SELECT COLUMN1, COLUMN2, COUNT(*) FROM TABLE WHERE COLUMN3 IS

  • 0

I have the following query:

SELECT COLUMN1, COLUMN2, COUNT(*)  
FROM TABLE  
WHERE COLUMN3 IS NOT NULL  
    AND COLUMN4 = 1  
    AND COLUMN5 = 4  
    AND COLUMN6 = 43  
    AND COLUMN7 = $P{YEAR}  
    AND COLUMN8 = $P{IT}  
GROUP BY COLUMN1, COLUMN2  
ORDER BY COLUMN1 ASC  

I wonder if it is possible to do something like:

SELECT COLUMN1, COLUMN2, COUNT(*)  
FROM TABLE  
WHERE COLUMN3 IS NOT NULL  
    AND COLUMN4 = 1  
    AND COLUMN5 = 4  
    AND COLUMN6 = 43  
    AND COLUMN7 = $P{YEAR}  
    IF ($P{IT} != 'ALL') { AND COLUMN8 = $P{IT} }  
GROUP BY COLUMN1, COLUMN2  
ORDER BY COLUMN1 ASC  

In other words, I want to add to the where clause “AND COLUMN8 = $P{IT}” only if “$P{IT}” value is not “ALL”. This means if the report must filter by the column “COLUMN8” or not.

Do someone know if this is possible? Is there other approach that accomplish the work?

I tried to execute the above query but I got a ‘Compilation running time’.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:40:26+00:00Added an answer on May 27, 2026 at 6:40 am

    Yes, you can do that in iReport. But you need to look at it slightly differently. You need a second parameter. Keep $P{IT}, and add $P{IT_SQL}. Give $P{IT_SQL} a default value like this:

    $P{IT}.equals("ALL") ? "" : " AND COLUMN8 = '" + $P{IT} + "'"
    

    Then your query should look like this:

    SELECT COLUMN1, COLUMN2, COUNT(*)  
    FROM TABLE  
    WHERE COLUMN3 IS NOT NULL  
        AND COLUMN4 = 1  
        AND COLUMN5 = 4  
        AND COLUMN6 = 43  
        AND COLUMN7 = $P{YEAR}  
        $P!{IT_SQL} 
    GROUP BY COLUMN1, COLUMN2  
    ORDER BY COLUMN1 ASC
    

    That will give you the desired SQL (none!) when $P{IT} has the value “ALL”, and it will give you the desired SQL (COLUMN8 = ‘abc’) when $P{IT} has the value “abc”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following query: select column_name, count(column_name) from table group by column_name having
I have the following query: SELECT COUNT(*) FROM FirstTable ft INNER JOIN SecondTable st
I have the following query: SELECT DISTINCT w.name, count(*) FROM widgets AS w JOIN
I have following query in PostgreSQL: SELECT COUNT(a.log_id) AS overall_count FROM Log as a,
I have the following query: SELECT m.*, COUNT(c.chapter_nr) as chapters, MAX(c.chapter_nr) as latest_chapter FROM
I have following SQL query that selects some results from my table: select avg(c3),
I have the following query: SELECT dm.app_id, apt.app_name, COUNT(dm.app_id) FROM dm_openapp dm JOIN app_table
I have the following query: SELECT location, step, COUNT(*), AVG(foo), YEAR(start), MONTH(start), DAY(start) FROM
I have defined the following query: select count((select * from producers)) from producers; Assuming
I have the following MySQL query: SELECT (COUNT(id) * 5) AS total FROM content

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.