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

  • Home
  • SEARCH
  • 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 8293661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:54:12+00:00 2026-06-08T13:54:12+00:00

When I need to store the result of a SQL sentence in a variable

  • 0

When I need to store the result of a SQL sentence in a variable I can use a code like so

declare @Max as int
set @Max=(select max(field_name) from table_name)

But now i wondering if is possible do the same for multiple variables for example for a sentence like

select max(field_name), min(field_name) from table_name

how i can store the result in two variables called @Max and @Min?

I know which this can be done using cursors

DECLARE @Max as int, @Min as int
DECLARE cursor_minmax CURSOR FOR
Select max(field_name), min(field_name) from table_name
OPEN cursor_minmax 
FETCH NEXT FROM cursor_minmax  INTO @Max,@Min
CLOSE cursor_minmax 
DEALLOCATE cursor_minmax 

but i want to know if is possible assign that values wihout use cursors.

  • 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-08T13:54:15+00:00Added an answer on June 8, 2026 at 1:54 pm

    You can do this as:

    select @max =  max(field_name), @min = min(field_name)
    from table_name
    

    I see . . . your confusion is that you want to use “set”. You can only set one value with “set”. You can set as many values as you like with “select”.

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

Sidebar

Related Questions

I need to store the result set of a stored procedure in a temporary
Below is pseudo-code for SQL Server stored procedure I need to write: int[] followers
I am using Ruby on Rails and I need to store a search result
I need to access the result of a stored procedure within a select statement,
I need store just 10 arrays in my app, which I can change from
I need to store user credentials in my app. I can store and retrieve
I'm new to PHP and SQL, but I need a way to store the
My requirement is to store the result of an sqlplus operation into a variable
I need to store a (large) SQL query in a column of a table
I need to Convert Strings stored in my Database to a Numeric value. Result

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.