473,396 Members | 2,089 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,396 software developers and data experts.

Stored procedures for selecting the data from databse & displaying on selction

Hi,
I have 4 columns workID, Description, work & Rework . On the basis these four columns i have to generate four more columns as total Work,%work, %Rework, %Total Work. we have some dummy data. So Now my question is how to write stored pocedure to select in case of the above scenaraio.
Thnks.
Dec 31 '09 #1

✓ answered by Atli

Hey.

If I am understanding you correctly, you don't really need a procedure.
You could simply do something like:
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.     `id`, `description`, `work`, `rework`,
  3.     (`work` + `rework`) AS `total_work`,
  4.     (`work` / (`work` + `rework`) * 100) AS `% work`,
  5.     (`rework` / (`work` + `rework`) * 100) AS `% rework`,
  6.     ((`work` + `rework`) / (SELECT SUM(`work` + `rework`) FROM `work_table`) * 100) AS `% total work`
  7. FROM `work_table`;

1 1495
Atli
5,058 Expert 4TB
Hey.

If I am understanding you correctly, you don't really need a procedure.
You could simply do something like:
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.     `id`, `description`, `work`, `rework`,
  3.     (`work` + `rework`) AS `total_work`,
  4.     (`work` / (`work` + `rework`) * 100) AS `% work`,
  5.     (`rework` / (`work` + `rework`) * 100) AS `% rework`,
  6.     ((`work` + `rework`) / (SELECT SUM(`work` + `rework`) FROM `work_table`) * 100) AS `% total work`
  7. FROM `work_table`;
Dec 31 '09 #2

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

Similar topics

4
by: Michael Trosen | last post by:
Hi Everyone, I hope someone can help, I'm pretty new to pro*c programming. I have the following application setup: a pro*c program calls a stored procedure and recieves a cursor back: the...
5
by: Rob Wire | last post by:
For the code below, how could I add an item in the drop down lists for both company and location to be an "All" selection that would send to the stored proc. spRptAttachments a value of "%" so...
1
by: mandible | last post by:
Hello I was wondering if I"m doing something wrong with using db2advis I have 2 stored procedures are are massive, I created an input file to call both of these stored procedures and I dont' seem...
0
by: ccorbett | last post by:
Hi, I am pretty new to microsoft programming environment. I want to create forms in visual basic 2005 studio that read data from stored procedures and load into the forms for editing and new...
3
by: Sirisha | last post by:
Hi, I am inserting values into databse using sqlserver stored procedures. i wrote stored preocedure,but in codebehind file(.vb file) i dont know how to pass the parameters, i got error message...
0
by: Sirisha | last post by:
Hi, I am inserting values into databse using sqlserver stored procedures. i wrote stored preocedure,but in codebehind file(.vb file) i dont know how to pass the parameters, i got error message...
12
by: brwalias | last post by:
Hi, using .net 2 sql server 2005 Here is my situation: I'm passing a variable in the url from a selection on Page A and need to display the results on the Results page be based on that...
0
by: Ryan | last post by:
PLEASE HELP!! I am trying to do what I think should be the simplest thing. In Visual Studio 2005, I set up a datagrid and then went ot configure a datasource for it. I made my connection to...
2
by: COHENMARVIN | last post by:
I found that I'm making an error in my 'case' statements, and now I want to go through a database full of many stored procedures to find that error in some of them and to fix it. Is there any way...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.