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 8492191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:38:52+00:00 2026-06-10T22:38:52+00:00

I have here simple query using group function.Here is the query SELECT DECODE (DIRAPP,

  • 0

I have here simple query using group function.Here is the query

SELECT DECODE (DIRAPP, NULL, 'SML', DIRAPP) DD
  FROM (SELECT      'At Director Approval '
                 || NVL (COUNT (*), 0)
                 || ' Cheques of Rs. '
                 || NVL (TO_CHAR (SUM (BPV_AMT), '9,999,999,999'), 0)
                 || ' in '
                 || CONCATENATE_LIST
                                 (CURSOR (SELECT DISTINCT NVL
                                                             (BPV_DTE,
                                                              SYSDATE
                                                             ) BPV_DTE
                                                     FROM CHECK_DATA
                                                    WHERE STA_FLG IN (1, 3)
                                                 ORDER BY 1 DESC
                                         )
                                 ) DIRAPP
            FROM CHECK_DATA
           WHERE STA_FLG IN (1, 3)
        GROUP BY 1, 2) A

I have used the nvl function and also decode but when no data found against the flags 1 and 3 then nothing is shown even 0 from nvl and also working decode.I want to show the whole string with as At Director Approval 0 Cheques of Rs.0 Please any one help me to do this

  • 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-06-10T22:38:53+00:00Added an answer on June 10, 2026 at 10:38 pm

    decode isn’t broken, it just has no data to work with. You are filtering on where sta_flg in (1,3), so if there are no records with either status, there are no rows at all. You can’t decode what doesn’t exist.

    One way around this is to change the way you’re counting and summing the values so that the filtering is effectively done within the select, not the where. Removing the formatting for a moment, rather than doing:

    SELECT COUNT(*), SUM(BPV_AMT)
    FROM check_data
    WHERE sta_flag IN (1,3);
    

    … which will return no rows if there are no records with matching flags, even if there is other data in the table, you can do:

    SELECT SUM(CASE WHEN sta_flg IN (1,3) THEN 1 ELSE 0 END) AS rec_cnt,
        SUM(CASE WHEN sta_flg IN (1,3) THEN bpv_amt ELSE 0 END) AS bpv_amt_tot
    FROM check_data;
    

    As long as the table isn’t empty, this will return a single row of data, with either normal values or both rec_cnt and bpv_amt_tot set to zero.

    Plugging that in as an inner select your query might look like:

    SELECT 'At Director Approval '
        || rec_cnt
        || ' Cheques of Rs. '
        || TO_CHAR(bpv_amt_tot, '9,999,999,999')
        || CASE WHEN rec_cnt = 0 THEN NULL
            ELSE ' in ' || CONCATENATE_LIST(CURSOR(
                SELECT DISTINCT NVL(bpv_dte, SYSDATE)
                FROM check_data
                WHERE sta_flg IN (1, 3)
                ORDER BY 1 DESC
            )) END AS dirapp
    FROM (
        SELECT SUM(CASE WHEN sta_flg IN (1,3) THEN 1 ELSE 0 END) AS rec_cnt,
            SUM(CASE WHEN sta_flg IN (1,3) THEN bpv_amt ELSE 0 END) AS bpv_amt_tot
        FROM check_data
    );
    

    The case around the ' in ' || CONCATENATE_LIST(... part is just to avoid a trailing in appearing when there are no matching statuses.

    Since you aren’t selecting any non-aggregated columns, you don’t need a group by clause. (And the one you had was incorrect anyway – you can’t group by column positions, so group by 1,2 is grouping by two constant values, which doesn’t add anything).

    And finally, since you’re using concatenate_list() I assume you’re on a version earlier than 11gR2; if you are on the current version then the built-in listagg() would be simpler.

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

Sidebar

Related Questions

I have a very simple query: SELECT comments.* FROM comments WHERE comments.imageid=46 And this
Here is a simple scenario I am contemplating. I have a query that is
Here I have a simple php script which displays some values from a database
I have created my web socket server and client using this simple tutorial here
Using the guidelines here I have successfully queried a simple fusion table for some
I have query like this: SELECT `om_chapter`.`manganame` as `link`, (SELECT `manganame` FROM `om_manga` WHERE
I have a basic MySQL query: $getFeed = SELECT posts.postID, posts.postTitle, ..... FROM posts
I have the following query: SELECT IF(dissolution_date IS NULL, YEAR(CURDATE()) - YEAR(incorporation_date), YEAR(dissolution_date) -
I have the following query: SELECT tableOneId SUM(a+b+c) AS tableOneData, MIN(d) AS tableTwoData, FROM
Here is a sample access query which I have(query ref/name - abovequery) select column_date,

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.