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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:47:08+00:00 2026-05-22T21:47:08+00:00

I’m having trouble incorporating a bit of logic into a large SQL query. I’m

  • 0

I’m having trouble incorporating a bit of logic into a large SQL query. I’m using SQL Server Reporting Services 2005 with the Report Designer, and it only gives you one area to define a single SQL query to populate the report with. Hopefully someone can tell me what’s wrong with my syntax so I can get it running.

I need to not only select a bunch of attributes filtering by (QuoteOrderStatus != ‘Closed’), but also to only count the quotes with (ItemStatus != ‘inactive’) in a COUNT(DISTINCT ItemID’s) statement (an aggregate function). I don’t want to simply filter out the quotes with inactive items, because I still want to display the quotes with zero items. I only want to not include them in the total itemCount.

I did research and it seems the way to accomplish this type of logic is using CASE statements, but I’m having trouble incorporating them into this one obfuscated query. Report Designer simply tells me it’s wrong and rearranges it to a way that I want even less. Can anyone help me with fixing this statement so it would be accepted as a valid query?

I’ve researched this for hours now without finding a good resource for this specific kind of problem. Sorry if the code is unclear, I tried to explain this as well as I can. Please ask questions if you want me to clarify in some way, and I appreciate any help anyone can offer.

SELECT DISTINCT 
    BIAdmin.Quote.QuoteOrderSalesOffice, BIAdmin.Quote.ManufacturerQuoteNumber, 
    BIAdmin.Quote.CustomerName, BIAdmin.Quote.Project_JobTitle, 
    BIAdmin.Quote.EndUserName, BIAdmin.Quote.QuoteOrderStatus,
    SUM(BIAdmin.Item.TotalPriceOfItemNumber) AS totalValue, BIAdmin.Item.ItemStatus
FROM BIAdmin.Quote LEFT OUTER JOIN BIAdmin.Item ON BIAdmin.Quote.ID = BIAdmin.Item.QuoteID
WHERE   BIAdmin.Item.ItemStatus LIKE
    CASE WHEN NOT (BIAdmin.Item.ItemStatus = 'inactive') THEN
    SELECT DISTINCT COUNT(BIAdmin.Item.ID) AS itemCount
GROUP BY BIAdmin.Quote.QuoteOrderSalesOffice, BIAdmin.Quote.ManufacturerQuoteNumber,
    BIAdmin.Quote.CustomerName, BIAdmin.Quote.Project_JobTitle,
    BIAdmin.Quote.EndUserName, BIAdmin.Quote.QuoteOrderStatus, BIAdmin.Item.ItemStatus
HAVING (NOT (BIAdmin.Quote.QuoteOrderStatus = N'[Closed]'))
  • 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-22T21:47:08+00:00Added an answer on May 22, 2026 at 9:47 pm

    I haven’t tried to unravel your whole statement, but it sounds like you want to use your CASE statement like this:

    SUM(CASE WHEN BIAdmin.Item.ItemStatus = 'inactive' THEN 0 ELSE 1 END) As ActiveItemCount
    

    This statement would go in your select clause rather than in your where clause. Using “Like” the way you isn’t going to work. Try taking it out altogether (and try it once without DISTINCT) and adding the sum above to see what your results look like.

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

Sidebar

Related Questions

No related questions found

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.