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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:55:51+00:00 2026-06-10T19:55:51+00:00

I am aware that you can assign a value to a variable within a

  • 0

I am aware that you can assign a value to a variable within a select by going

SELECT @blahBlah = (tbl.ProductGroup) 
FROM tbl

Ok, now what I need to do is as follow.

Each account/user has a set number of transactions allowed every day; eg. Account 1 can do 5 transactions and Account 2 can do 3.

So in a select that will determine whether this account has overshot its limit and by how many, we have numerous inSelect calculations to produce column data.

The problem is that we now have about 4 columns that will each do a nested select to get the limits from another table, in order to produce a value for the current one.

What would be ideal is to assign these limits to a @variable in the select statement and to only reference that variable within said statement if needed.

To give a brief example (not actual logic):

SELECT
  @Limit = (SELECT Limit From tClient Where tClient.clientId = tbl.ClientId),
  (select count(*) from batch where batchItemCount > @limit) AS BadBatches,
  ....
FROM TBL

You get the picture.

Is there some method to pull this off?

  • 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-10T19:55:52+00:00Added an answer on June 10, 2026 at 7:55 pm

    Yes, you can use a Common Table Expression(CTE) to do these sort of things. The following is the basic idea that you can tweak to get it work for your case:

    ;WITH limtis AS
    (
       SELECT Limit, ClientId
       From tClient 
       Where tClient.clientId = tbl.ClientId
    )
    select ...
    from batch
    INNER JOIN Limtis On ...
    WHERE ...
    

    Hope you got the picture.

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

Sidebar

Related Questions

Now I am aware that I probably need to use a ListBox and can
I am aware that I can't dynamically refer to a variable (eg. 'var &
I am aware that I can set null like string val = null; But
I am aware that I can access all external links on a page using
I'm aware that I can check an ActiveRecord through the rails console but it
I'm aware that you can do this: public ActionResult DoSomething([Bind(Exclude = CreationDate)] Item item)
I am aware that you can probably build a lower version of .NET, but
I am aware that you can generate create scripts to generate database objects, but
I'm aware that I can <exec executable=cp failonerror=true> , however, I'd really rather have
I am aware that you can 'remotely' script android using port forwarding, using the

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.