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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:44:23+00:00 2026-06-01T03:44:23+00:00

How would I rewrite this query to be performant by executing the SQL function

  • 0

How would I rewrite this query to be performant by executing the SQL function only once?

SELECT Top 1 Id, Name
  FROM Users U 
       INNER JOIN UserDetail D on U.Id = D.Id
       LEFT OUTER JOIN CreditCards C ON C.Id = U.Id AND UserHasCC(U.Id) = 1
       LEFT OUTER JOIN CreditCardDetails CD on C.CCID = C.CCID AND UserHasCC(U.Id) = 1
WHERE
       ((CD.active = 1 and UserHasCC(U.Id) = 1) OR UserHasCC(U.Id) = 0) and
       U.active = 1 and
       ((C.IsInternational = 1 and UserHasCC(U.Id) = 1) OR UserHasCC(U.id = 0)

Basically, the query gets all users that don’t have credit cards and those that have active international credit cards.

  • 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-06-01T03:44:25+00:00Added an answer on June 1, 2026 at 3:44 am

    This looks like it accomplishes the same logic.

     SELECT Top 1 Id, Name
      FROM Users U 
           INNER JOIN UserDetail D on U.Id = D.Id
           LEFT OUTER JOIN CreditCards C ON C.Id = U.Id 
           LEFT OUTER JOIN CreditCardDetails CD on C.CCID = C.CCID 
       WHERE
             U.active = 1
             AND
             (
                 UserHasCC(U.Id) = 0
                 OR
                 (
                    UserHasCC(U.Id) = 1
                    and
                    (
                      C.IsInternational = 1
                      OR
                      CD.active = 1
                    )
    
             )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would i rewrite this rails query to run on Heroku (Portegres) @students =
The original query looks like this (MySQL): SELECT * FROM books WHERE title LIKE
I thought I would rewrite this question (same iteration). The original was how to
I am wanting to rewrite a url like: http://my.project/mydomain.com/ANY_NUMBER_OF_CATEGORIES/designer/4/designer-name/page.html to this: http://my.projects/mydomain.com/ANY_NUMBER_OF_CATEGORIES/page.html?designer=4 I would
I can only find mod rewrite examples/tutorials for query's, so can someone help me
I have a following query (simplified): SELECT Id FROM dbo.Entity WHERE 1 = ALL
I have a query which is crossing two tables select count(*) from ingenium.empevt, ingenium.evt
I have this URL: oldsite.example/profile.php?uid=10 I would like to rewrite it to: newsite.example/utenti/10 How
I have a Wordpress page that accepts a query string argument: http://x.com/page-name/?parameter=value This works
I have found this query to calculate medians @myvar:=0; @rownum:=0; SELECT result.readdate, AVG(total_gallons) AS

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.