473,508 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Set Variable From Query Results

233 New Member
I have a stored procedure with a query that selects multiple values, each of which I would like to assign to local variables. I am aware of how to set a single local variable by way of SET @variable1 = SELECT * FROM TABLE WHERE Column = 'unique value', but as I said, this only works for single variables.

My initial thoughts were if it were possible to do something such as:

DECLARE @variable1, @variable2

SELECT column1, column2
FROM table1
WHERE column1 = 'unique value'

SET @variable1 = column1
SET @variable2 = column2

Obviously this does not work, but I am hoping that there is a method to accomplish something like this.
Mar 5 '08 #1
3 20104
deepuv04
227 Recognized Expert New Member
I have a stored procedure with a query that selects multiple values, each of which I would like to assign to local variables. I am aware of how to set a single local variable by way of SET @variable1 = SELECT * FROM TABLE WHERE Column = 'unique value', but as I said, this only works for single variables.

My initial thoughts were if it were possible to do something such as:

DECLARE @variable1, @variable2

SELECT column1, column2
FROM table1
WHERE column1 = 'unique value'

SET @variable1 = column1
SET @variable2 = column2

Obviously this does not work, but I am hoping that there is a method to accomplish something like this.
[cdoe = sql]

you can assign values to multiple variables as
SELECT @variable1 = column1, variable2 = column2
FROM table1
WHERE column1 = 'unique value'


[/code]
Mar 5 '08 #2
mcfly1204
233 New Member
[cdoe = sql]

you can assign values to multiple variables as
SELECT @variable1 = column1, variable2 = column2
FROM table1
WHERE column1 = 'unique value'


[/code]
You know, I just read an article about the differences between set and select, and I read about how set cannot assign multiple variables values, but select can. I have no idea why this did not click. Thanks for the response though.
Mar 5 '08 #3
ck9663
2,878 Recognized Expert Specialist
One catch (there might be some that I don't know about), Deepuv writes:
Expand|Select|Wrap|Line Numbers
  1. WHERE column1 = 'unique value'
on the code because he's stressing your query should return only one row. Otherwise, you might have unexpected values on your variables.

-- CK
Mar 5 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
9616
by: Wayne Baswell | last post by:
I want to pass a date variable to a sql statement from Crystal Reports. The part of the query accepting the variables looks like: "Calendar_Date between To_Date('1-JUN-03','mm/dd/yy') and...
1
2507
by: Greg | last post by:
How can I use a variable as the table name?
4
1862
by: s99999999s2003 | last post by:
hi the database "execute" function returns a list of logical results. Each logical result is a list of row tuples, as explained in the documents. everytime i use it to execute various...
1
1439
by: Jan | last post by:
Hi, I'm trying with a query. A criteria of the query is a global variable represented as a function. The variable is the result of a multiselect listbox. The function looks like this: Public...
3
1544
by: Eli Criffield | last post by:
I'm getting odd results from my fuction that takes variable aguments. What i want to do is take a printf like format and pass that to mysql_query then i do some processing of the results and...
6
4815
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
2
1931
by: milo1955 | last post by:
I have a form that passes a single variable via the GET function to a mysql databse query with the results paginated. The first page of the results work fine, but the link to the second page yields...
11
7342
by: Purdue02 | last post by:
I am trying to pass a global variable to criteria in a query using the below code, but the query is returning no results. I have the function ReturnStrCriteria() included in the query's criteria....
2
4652
by: Whasigga | last post by:
Hello I am working on a project to export data from a query into an Excel file. I have a form with a button on it and the button when clicked runs a function that is supposed to run the query and...
1
4823
by: pretzelboy | last post by:
Hi, I last wrote software 13years ago in the pascal, dbase, clipper days. I have recently built a Ubuntu Box and with C++ (and help from the web) setup a serial barcode reader program using Mysql...
0
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5045
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.