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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:29:17+00:00 2026-05-18T06:29:17+00:00

I have the following query: ;WITH valRules AS ( SELECT vr.valRuleID, Count(*) AS totalRows,

  • 0

I have the following query:

;WITH valRules AS   
(   SELECT vr.valRuleID, Count(*) AS totalRows, Sum(vt.test) AS validRows  
    FROM (SELECT NULL AS x)    AS x  
    JOIN #itemMap              AS IM  
      ON IM.lngitemID       = 1  
    JOIN tblValidationRule     AS vr  
      ON IM.RuleID          = vr.valRuleID  
    JOIN tblValidationRuleDetl AS vrd  
      ON vr.valRuleID       = vrd.valRuleID
    LEFT JOIN #ValTest         AS vt  
      ON vrd.type           = vt.type     
     AND vrd.typeSequence   = vt.typeSequence  
     AND vrd.valRule        & vt.Response > 0   
     OR (vrd.valrule = 0 AND vt.response = 0 )  
     GROUP BY vr.valRuleID  
)  
SELECT Count(*)   
    FROM valrules  
    WHERE totalrows = validRows

Note the CTE, and the Bitwise Operator in the Left Join Condition. How this is currently used is in a stored procedure that takes values from a C# application in the form of an XML variable. The XML Variable is placed into table #valTest. All columns are of datatype INT. If vt.Response is valid for vaRule, the result of & will be greater than zero. (i.e. 31 & 8 = 8 but 12 & 2 = 0). vt.Test column contains the number 1 for each row, so that it may be summed up (nulls are automatically excluded) to get a count of the validations that pass by rule. Each rule has a number of attributes that must pass validation for success. If the number of attributes is equal to those that passed, we have success.

In an effort to reduce calls to the database, the goal is to cache ALL the rules in the ASP.NET cache and handle validation localy. The developers are asking for a de-normalized version of the validation data with the claim that the SQL Set based operation is not a simple task in C# with Linq. From what I have looked into, I would agree. At this point my investigation shows the bitwise comparison in the join condition is particularly problematic.

The main question is how is can this be converted to something that uses Linq on the C# side? Or, are there more efficient ways to deal with this on the client side and Linq is not one of them (i.e. just give them flat data)?

thanks

  • 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-18T06:29:18+00:00Added an answer on May 18, 2026 at 6:29 am

    LINQ-to-SQL isn’t going to do anything quite as bespoke as that query. Which isn’t a criticism of either LINQ-to-SQL or the query: simply, there are limits.

    There are two ways I would approach that:

    1: as a parameterized TSQL query via ExecuteQuery<T> – i.e.

    var result = db.ExecuteQuery<YourType>(@"your query here with {0}, {1} etc",
                     arg0, arg1, ...);
    

    2: write that TSQL a udf mapped into the data-context:

    var result = db.YourUdf(arg0, ...);
    

    Both are valid and will work with LINQ-to-SQL; personally I prefer the first approach, but the UDF approach allows greater re-use within the DB layer, at the expense of having more complex deployment (i.e. app tier and db tier all at the same time).

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

Sidebar

Related Questions

i have following query SELECT *, count(jx_commissions.commission_amount) AS summe FROM jx_members INNER JOIN jx_commissions
I have following query working : SELECT COUNT(id), AgeRange FROM ( select id, case
I have following query in PostgreSQL: SELECT COUNT(a.log_id) AS overall_count FROM Log as a,
I have the following query: SELECT * FROM my_users as U RIGHT JOIN subscribers
I have the following query: select column_name, count(column_name) from table group by column_name having
I have the following query: SELECT c.* FROM companies AS c JOIN users AS
I have following query select id, nameOfPet, count(fed) from petLover, pets where id =
I have following MySQL query: (SELECT c.Channel as name, count(*) as total_episode FROM (
I have following query: $query=SELECT language_value, votes, user_id FROM labels WHERE approved=1 AND label_value=.
I have following query , select * from process where name like 'abc'; now

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.