dunkin1969
asked on
How to Loop Through a Table in SQL and apply a Calculation to each record
Hi Experts,
I have MyTable with Column1 (X) containing test scores 1 through 100 (1,2,3,...100)
I want each row to be used to calculate (Y) in the formula: Y = 2X+1
So my results will look like this:
X Y
1 3
2 5
3 7
4 9
5 11
etc
etc
How would I write a loop for this?
Thanks you!
I have MyTable with Column1 (X) containing test scores 1 through 100 (1,2,3,...100)
I want each row to be used to calculate (Y) in the formula: Y = 2X+1
So my results will look like this:
X Y
1 3
2 5
3 7
4 9
5 11
etc
etc
How would I write a loop for this?
Thanks you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why would you want to store this number, when you can compute it in a query at any time? Generally, storing computed values is a bad idea. Not always, but generally.
ASKER
oh by the way, let's say I don't have a table... and I want the same results using X = 1 through 100. How would i do that? Some type of counter?
Let me know if this should be posted as a new topic. THANK YOU !!!
Let me know if this should be posted as a new topic. THANK YOU !!!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
many thanks!
ASKER