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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:50:57+00:00 2026-05-18T01:50:57+00:00

How we can group the result of the query depending up on the parameter

  • 0

How we can group the result of the query depending up on the parameter passed.

A small stored procedure is shown below. parameter Param is passed to the procedure.

If param value is “f” the result must group by starttime otherwise by using formid. How can i do this. ???I tried the code show below but its not working .

DROP PROCEDURE IF EXISTS Test;
CREATE PROCEDURE Test (Param VARCHAR (2))


 BEGIN
  SELECT formid, starttime
    FROM tbevaluationscoreinfo
   CASE Param
     when 'F'
      then group by starttime;
     else
      group by formid;

   end
END;
  • 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-18T01:50:58+00:00Added an answer on May 18, 2026 at 1:50 am

    One way is to move branching up a level:

    IF Param = 'F' THEN
      SELECT starttime, count(formid)
      FROM tbevaluationscoreinfo
      GROUP BY starttime;
    ELSE
      SELECT formid, count(starttime)
      FROM tbevaluationscoreinfo
      GROUP BY formid;
    END IF;
    

    Another, less recommended solution, is dynamic SQL.

    And the third possible solution is:

    SELECT
      case Param when 'F' then starttime else formid end as group_column,
      count(formid),
      count(starttime)
    FROM
      tbevaluationscoreinfo
    GROUP BY
      group_column;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I query the tfs history to have this result: group the resources
How can I group a query result by a field that is not saved
How can I group result of a LINQ to SQL query by hours considering
Can any one tell, how to get the result of LINQ query contains group
Can I Limit Group Items in the Content Query WebPart so that the output
How can I add ROW numbers to this query result? SELECT DISTINCT VehicleSpecs.SubmittedById, COUNT(VehicleSpecs.SubmittedById)
I can do this by looping the result of a simplified query: var query
I'm getting an unexpected result for my query in group function. I'm using the
Trying to work with groupby so that I can group together files that were
How can I group a number of Dispatcher.Invoke and wait for one group to

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.