473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Set variable to value in column

Is it possible to set a variable in a stored procedure equal to a
value from a column when that column's respective ID is equal to
max(id)-1
ID A B
1 24 24
2 53 29
3 76 47
4 32 32

What I am trying to do is update A in the last column to be equal to B
from the 4th row, plus A from the 3rd row. If I could set a variable
equal to A in row 3 (in this case 76) I could easily add the variable
to the existing value.

I've tried something like this before. I'm sure some of you will say
right away, "of coarse that doesn't work". I'm new to sql.

Set A = A + select( B from mytable where ID = (select (max(ID)-1) from
mytable))
where ID = (select (max(ID)) from mytable)

Thanks

Matt

Jul 26 '07 #1
1 7091
I think you have columns and rows confused in your first paragraph. I
also can't quite figure out what you mean by variables, as A is both
(apparently) a column in the table and something you are trying to
SET.

This query might give you something to play with.

SELECT X.A +
(SELECT X
FROM YourTable as Y
WHERE Y.ID =
(select max(ID) FROM YourTable as Z
where Z.ID < A.ID))
FROM YourTable as X
WHERE A.ID =
(select max(ID) FROM YourTable)

Roy Harvey
Beacon Falls, CT

On Thu, 26 Jul 2007 20:08:43 -0000, mcolson <mc*********@gmail.com>
wrote:
>Is it possible to set a variable in a stored procedure equal to a
value from a column when that column's respective ID is equal to
max(id)-1
ID A B
1 24 24
2 53 29
3 76 47
4 32 32

What I am trying to do is update A in the last column to be equal to B
from the 4th row, plus A from the 3rd row. If I could set a variable
equal to A in row 3 (in this case 76) I could easily add the variable
to the existing value.

I've tried something like this before. I'm sure some of you will say
right away, "of coarse that doesn't work". I'm new to sql.

Set A = A + select( B from mytable where ID = (select (max(ID)-1) from
mytable))
where ID = (select (max(ID)) from mytable)

Thanks

Matt
Jul 26 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nelson Broat | last post by:
In jsp land you can have the following: <% String name = "Nelson"; %> Hi, my name is <%= name %>. Such that, in your browser you see:
1
by: RayP | last post by:
I'd appreciate some help I'm having trying to run a cursor. First, some background. The Status field of all records on Table A needs changing from 1 to 0 where there is no corresponding record...
20
by: MLH | last post by:
120 MyString = "How many copies of each letter do you need?" 150 MyVariant = InputBox(MyString, "How Many?", "3") If MyVariant = "2" Then MsgBox "MyVariant equals the string '2'" If...
6
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 ...
3
by: sparks | last post by:
tempname = FindSpaces(rs!) this works fine but if I try to pass a variable value to it For i = 1 To 3 Step 2 tempname = FindSpaces(rs!) why can't the variable i just be used in this way? Is...
3
by: Mrozu | last post by:
Hi How can I include in name of my variable value of other variable? I have following code: For x = 0 To 10 Dim column As New DataGridTextBoxColumn column.MappingName = magazyny(x)
5
by: aamirghanchi | last post by:
Hi, I need to know if anyone else came across this. The Session variable value I set in a sortCommand event handler of a datagrid does not hold on till the next sortcommand event handler and...
3
by: chandra.krothapalli | last post by:
Hi, I am writing a program to read database logs using db2Readlog/ db2ReadLogNoConn API. I am able to parse the data of "FIXED format data" and link them to appropriate columns for a given...
3
by: TB | last post by:
On a user control (ascx) I have a datagrid with a hyperlink column containing the following code: <asp:HyperLinkcolumn headerstyle-width="80px" ItemStyle-Width="80px" DataNavigateUrlField="ID"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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...
0
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
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,...

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.