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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:34:14+00:00 2026-06-11T15:34:14+00:00

I am making a storedprocedure which has a SELECT clause selecting multiple colums from

  • 0

I am making a storedprocedure which has a SELECT clause selecting multiple colums from some joined tables. For one of these colums the value is depending on a condition with CASE.

SELECT DISTINCT
 table1.col1 as var1,
 table2.col2 as var2,
 CASE WHEN (FLOOR(table3.col3/0.2)*0.2) > 20 THEN 20
      WHEN (FLOOR(table3.col3/0.2)*0.2) <= 20 THEN FLOOR(table3.col3/0.2)*0.2
      ELSE table3.col4 -- selecting another value is the 
                       -- value in table3.col3 is null
      END as var3 
FROM ... 
WHERE ...

As you can see in the select I’m doing three times the FLOOR(table3.col3/0.2)*0.2 calculation. Is it possible to store this calculated value in a variable WITHIN THE SELECT and then use this variable in the conditions?

Thanks in advance,

Jeroen

  • 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-11T15:34:15+00:00Added an answer on June 11, 2026 at 3:34 pm

    No, you can reduce it to 2 calls like below. But whatever else you will do will be more costly then actually doing it like this, as what you do there is very fast. You can think on something to improve, when you actually have some heavy operations. This is just nothing. You might also make a get_min function but again I do not think it will be worth it.

    With 2 calls:

    case when table3.col3 then table3.col4
         when (FLOOR(table3.col3/0.2)*0.2) > 20 THEN 20
         else FLOOR(table3.col3/0.2)*0.2
    end
    

    With min function:

    case when table3.col3 then table3.col4
         else dbo.get_min(FLOOR(table3.col3/0.2)*0.2,20)
    end
    

    As a side note, the min function I am referring to has to be built (user defined function).

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

Sidebar

Related Questions

I'm making one MySql script that break one string field in multiple words. I
Making an adobe flex ui in which data that is calculated must use proprietary
I am making a number of distinct controllers, one relating to each stored procedure
I am making MSSQL stored procedure CLR calls from ASP pages. When an exception
I'm trying to query a dataset from a stored-procedure but I'm making a mess
I have two stored procedures, one of which returns a list of payments, while
I'm making a Stored Procedure that basically concatenates a long string with data from
I am running an app C#, WPF and the manager is making some changes
Actually i am facing a problem calling a stored procedure and making some changes
I'm currently making a stored procedure which offers the user a filter system to

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.