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

  • Home
  • SEARCH
  • 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 1112295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:41:13+00:00 2026-05-17T02:41:13+00:00

I am using a subquery to return a count as an integer value to

  • 0

I am using a subquery to return a count as an integer value to my main query. This query is used to rebind an ASP.NET DataGrid and I have only two characters width available for this column. I want to restrict the width to two characters. So, I want to set a value of 99 when the count exceeds 99. I can’t figure a way to do this? I can’t see how to apply a case statement here.

SELECT
     MEMB_ID,
     MEMB_Name,
     SELECT COUNT(*)
 FROM SessionOrder
WHERE SessionOrder.SORD_MEMB_ID = m.MEMB_ID 
  And SessionOrder.SORD_NumberCompleteDownloads <> 0
     As MEMB_Downloads,
     MEMB_JoinDate
FROM Member

How can this be done?

  • 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-17T02:41:14+00:00Added an answer on May 17, 2026 at 2:41 am

    The CASE expression can look like this:

    CASE WHEN COUNT(*) > 99 THEN 99 ELSE COUNT(*) END
    

    There appear to be a couple of errors with your existing query (for example m is not defined). With these errors corrected and the above change made the resulting query could look like this:

    SELECT
         MEMB_ID,
         MEMB_Name,
         (
             SELECT CASE WHEN COUNT(*) > 99 THEN 99 ELSE COUNT(*) END
             FROM SessionOrder
             WHERE SessionOrder.SORD_MEMB_ID = MEMB_ID 
             AND SessionOrder.SORD_NumberCompleteDownloads <> 0
         ) AS MEMB_Downloads,
         MEMB_JoinDate
    FROM Member
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query that inserts rows, using a subquery like so: INSERT INTO
I have a query that is currently using a correlated subquery to return the
I am stuck on an update query that is using a subquery and have
How to set default VALUE in SubQuery result using mysql SELECT p.`id`, p.`name`, p.`class_name`,
I'm using .NET 4 and the Entity Framework to construct a simple query. Here's
I have the following SQL query to return all Customers who have no OrderLines
I am trying to query the following HQL using GORM: MailMessage.executeQuery(toId, count(toId) from (SELECT
I'm using this query to get all employees of {clients with name starting with
I am attempting to SELECT rows from a table using a query like this
I'm currently using the following query (simplified indeed) : SELECT ( SELECT COUNT(id) FROM

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.