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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:57:05+00:00 2026-05-16T14:57:05+00:00

following background: i have a Table-valued Function that returns a Table that is a

  • 0

following background: i have a Table-valued Function that returns a Table that is a kind of filtered view(views can not be parameterised) on a large table. Now i need many row count values on different conditions. Is it possible to get all count values in one query without having to query this function for every condition?

For the sake of completeness(it doesnt really matter, you may read over it), this is the function:

CREATE FUNCTION [dbo].[getRuleConfigBySetSlsRules] (
 @fiRuleSet AS TinyInt,
 @fiServiceLocations AS NVARCHAR(4000),
 @fiRules AS NVARCHAR(400)
)

RETURNS TABLE AS RETURN  (
 SELECT     ruleChangeTo.fiSet, ruleChangeTo.fiClaimStatus, ruleChangeTo.fiRule, ruleChangeTo.fiSL, ruleChangeTo.fiResult, 
                      dimClaimStatus.ClaimStatusName AS OldStatus, dimClaimStatus_1.ClaimStatusName AS NewStatus, locSL.SLName, ruleSet.SetName, 
                      ruleResult.ResultName, locMarketUnit.MarketUnitName, locCountry.CountryName, ruleRule.RuleKey, ruleRule.RuleName, ruleRule.RuleDescription, 
                      locGSP.WCMSName AS GSP_WCMSName, locGSP.Active AS GSP_Active, locGSP.WCMSKeyNumber AS GSP_WCMSKeyNumber, 
                      locSL.Active AS SL_Active, locSL.WCMSName AS SL_WCMSName, locSL.WCMSKeyNumber AS SL_WCMSKeyNumber, locSL.fiSLType, 
                      locSLType.SLTypeName, ruleChangeTo.fiClaimStatus_ChangeTo
FROM         locGSP INNER JOIN
                      locCountry ON locGSP.fiCountry = locCountry.idCountry INNER JOIN
                      locMarketUnit ON locCountry.fiMarketUnit = locMarketUnit.idMarketUnit INNER JOIN
                      locSL ON locGSP.idGSP = locSL.fiGSP INNER JOIN
                      ruleChangeTo ON locSL.idSL = ruleChangeTo.fiSL INNER JOIN
                      dimClaimStatus ON ruleChangeTo.fiClaimStatus = dimClaimStatus.idClaimStatus INNER JOIN
                      ruleResult ON ruleChangeTo.fiResult = ruleResult.idResult INNER JOIN
                      ruleRule ON ruleChangeTo.fiRule = ruleRule.idRule INNER JOIN
                      ruleSet ON ruleChangeTo.fiSet = ruleSet.idSet INNER JOIN
                      locSLType ON locSL.fiSLType = locSLType.idSLType INNER JOIN
                      dimClaimStatus AS dimClaimStatus_1 ON ruleChangeTo.fiClaimStatus_ChangeTo = dimClaimStatus_1.idClaimStatus  INNER JOIN
                       dbo.Split(@fiServiceLocations, ',') AS ServiceLocations ON ServiceLocations.Item = ruleChangeTo.fiSL INNER JOIN
                      dbo.Split(@fiRules, ',') AS Rules ON ruleChangeTo.fiRule = Rules.Item
WHERE (ruleChangeTo.fiSet = @fiRuleSet)
)

And in the following way i can get one count-value, but in fact i need 30 conditions on the same query(the WHERE-clause).

alt text

What is the best way to accomplish this in a strong typed dataset without one query for every value? I dont catch that.
This is the query that must be extended(out of the above image)with various status-conditions and their count values:

SELECT     COUNT(*) AS CountValidReject
FROM         dbo.getRuleConfigBySetSlsRules(@fiSet, @ServiceLocations, @Rules) AS RuleConfigFilter
WHERE     (fiClaimStatus = 1) AND (fiClaimStatus_ChangeTo = 8)

To come to the point: do i need a stored-procedure with a temp-table or something like that or can i create and query a temp table in this sql in the Dataset? I don’t want to call getRuleConfigBySetSlsRules for every value.

Thanks

EDIT:
This is the final query which returns 1 row with many count-values as columns. Thanks to Steve again for the CASE WHEN hint. Its very efficient.

SELECT  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 5) AND (fiClaimStatus_ChangeTo = 2) THEN 1 ELSE NULL END) AS RuleAppliesApprovedInvalid,
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 5) AND (fiClaimStatus_ChangeTo = 8) THEN 1 ELSE NULL END) AS RuleAppliesApprovedReject,
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 5) AND (fiClaimStatus_ChangeTo = 7) THEN 1 ELSE NULL END) AS RuleAppliesApprovedReview, 
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 9) AND (fiClaimStatus_ChangeTo = 2) THEN 1 ELSE NULL END) AS RuleAppliesEscalatedInvalid, 
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 9) AND (fiClaimStatus_ChangeTo = 8) THEN 1 ELSE NULL END) AS RuleAppliesEscalatedReject, 
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 9) AND (fiClaimStatus_ChangeTo = 7) THEN 1 ELSE NULL END) AS RuleAppliesEscalatedReview, 
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 9) AND (fiClaimStatus_ChangeTo = 1) THEN 1 ELSE NULL END) AS RuleAppliesEscalatedValid, 
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 8) AND (fiClaimStatus_ChangeTo = 2) THEN 1 ELSE NULL END) AS RuleAppliesRejectInvalid, 
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 8) AND (fiClaimStatus_ChangeTo = 1) THEN 1 ELSE NULL END) AS RuleAppliesRejectValid, 
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 7) AND (fiClaimStatus_ChangeTo = 2) THEN 1 ELSE NULL END) AS RuleAppliesReviewInvalid, 
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 7) AND (fiClaimStatus_ChangeTo = 8) THEN 1 ELSE NULL END) AS RuleAppliesReviewReject, 
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 7) AND (fiClaimStatus_ChangeTo = 1) THEN 1 ELSE NULL END) AS RuleAppliesReviewValid, 
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 1) AND (fiClaimStatus_ChangeTo = 5) THEN 1 ELSE NULL END) AS RuleAppliesValidApproved, 
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 1) AND (fiClaimStatus_ChangeTo = 2) THEN 1 ELSE NULL END) AS RuleAppliesValidInvalid, 
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 1) AND (fiClaimStatus_ChangeTo = 8) THEN 1 ELSE NULL END) AS RuleAppliesValidReject, 
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 1) AND (fiClaimStatus_ChangeTo = 7) THEN 1 ELSE NULL END) AS RuleAppliesValidReview, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 5) AND (fiClaimStatus_ChangeTo = 2) THEN 1 ELSE NULL END) AS RuleApplNotApprovedInvalid, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 5) AND (fiClaimStatus_ChangeTo = 8) THEN 1 ELSE NULL END) AS RuleApplNotApprovedReject, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 5) AND (fiClaimStatus_ChangeTo = 7) THEN 1 ELSE NULL END) AS RuleApplNotApprovedReview, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 9) AND (fiClaimStatus_ChangeTo = 2) THEN 1 ELSE NULL END) AS RuleApplNotEscalatedInvalid, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 9) AND (fiClaimStatus_ChangeTo = 8) THEN 1 ELSE NULL END) AS RuleApplNotEscalatedReject, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 9) AND (fiClaimStatus_ChangeTo = 7) THEN 1 ELSE NULL END) AS RuleApplNotEscalatedReview, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 9) AND (fiClaimStatus_ChangeTo = 1) THEN 1 ELSE NULL END) AS RuleApplNotEscalatedValid, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 8) AND (fiClaimStatus_ChangeTo = 2) THEN 1 ELSE NULL END) AS RuleApplNotRejectInvalid, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 8) AND (fiClaimStatus_ChangeTo = 1) THEN 1 ELSE NULL END) AS RuleApplNotRejectValid, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 7) AND (fiClaimStatus_ChangeTo = 2) THEN 1 ELSE NULL END) AS RuleApplNotReviewInvalid, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 7) AND (fiClaimStatus_ChangeTo = 8) THEN 1 ELSE NULL END) AS RuleApplNotReviewReject, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 7) AND (fiClaimStatus_ChangeTo = 1) THEN 1 ELSE NULL END) AS RuleApplNotReviewValid, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 1) AND (fiClaimStatus_ChangeTo = 5) THEN 1 ELSE NULL END) AS RuleApplNotValidApproved, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 1) AND (fiClaimStatus_ChangeTo = 2) THEN 1 ELSE NULL END) AS RuleApplNotValidInvalid, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 1) AND (fiClaimStatus_ChangeTo = 8) THEN 1 ELSE NULL END) AS RuleApplNotValidReject, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 1) AND (fiClaimStatus_ChangeTo = 7) THEN 1 ELSE NULL END) AS RuleApplNotValidReview, 
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 1) THEN 1 ELSE NULL END) AS AllValidApplies, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 1) THEN 1 ELSE NULL END) AS AllValidNotApplies, 
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 5) THEN 1 ELSE NULL END) AS AllApprovedApplies,          
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 5) THEN 1 ELSE NULL END) AS AllApprovedNotApplies, 
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 7) THEN 1 ELSE NULL END) AS AllReviewApplies, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 7) THEN 1 ELSE NULL END) AS AllReviewNotApplies, 
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 7) THEN 1 ELSE NULL END) AS AllRejectApplies, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 7) THEN 1 ELSE NULL END) AS AllRejectNotApplies, 
  COUNT(CASE WHEN (fiResult = 1) AND (fiClaimStatus = 9) THEN 1 ELSE NULL END) AS AllEscalatedApplies, 
  COUNT(CASE WHEN (fiResult = 2) AND (fiClaimStatus = 9) THEN 1 ELSE NULL END) AS AllEscalatedNotApplies
FROM         dbo.getRuleConfigBySlsRules(@ServiceLocations, @Rules) AS RuleConfig
WHERE     (fiSet = @fiSet)
  • 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-16T14:57:05+00:00Added an answer on May 16, 2026 at 2:57 pm

    It would help a lot if you were more specific and gave an example. I’m not sure what “30 conditions on the same query(the WHERE-clause)” means or what “strongly typed” has to do with anything. Can you give two or three example of the 30 things you want?

    A guess at what you want is something like this:

    SELECT
      COUNT(CASE WHEN (fiClaimStatus = 1) AND (fiClaimStatus_ChangeTo = 8)
            THEN 1 ELSE NULL END) AS myCount1,
      COUNT(CASE WHEN (fiClaimStatus = 2) AND (fiClaimStatus_ChangeTo = 8)
            THEN 1 ELSE NULL END) AS myCount2,
      COUNT(CASE WHEN (fiClaimStatus = 2) AND (fiClaimStatus_ChangeTo = 6)
            THEN 1 ELSE NULL END) AS myCount1,
      ...
    FROM dbo.getRuleConfigBySetSlsRules(@fiSet, @ServiceLocations, @Rules) AS T
    

    If this isn’t close to what you need, please provide more information.

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

Sidebar

Ask A Question

Stats

  • Questions 516k
  • Answers 516k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use WcfOperationSessionContext (new in 3.0). Once bound, your Data classes… May 16, 2026 at 6:53 pm
  • Editorial Team
    Editorial Team added an answer This worked: $filename = realpath($_GET['filename']); if (strpos($filename, '/full/path/to/special') !== 0)… May 16, 2026 at 6:53 pm
  • Editorial Team
    Editorial Team added an answer This is a wild guess, but have you marked "Build… May 16, 2026 at 6:53 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have table cell which has class cellActive. Which has following defination .cellActive{background:#DDDDDD} Now
Some background: I have an database that I want to use linq-to-sql to update
Currently, I have the following class: #btnHelp { background: url(images/btnHelp.png) center no-repeat, -webkit-gradient(linear, left
I am learning Python (I have a C/C++ background). I need to write something
I'm trying to get an jquery ajax callback function to update the background colour
Using the example at the following URL: http://www.kavoir.com/2009/02/php-drop-down-list.html How can I have that drop
I have a table which has textboxes in its cells. All these textboxes are
I am creating a table (stats_1) dynamically and would like to have each row
Background: I have a unit of optimised Delphi/BASM routines, mostly for heavy computations. Some
I have a Silverlight application with some maps, and in the same page this

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.