Hi everyone
I have the below stored procedure and I want to select all columns to display them on the web form using "where clause" by specifying the "regno" provided by user in a textbook named txtboxsearch or "date from and to" by user selecting time on the displayed calender. The problem am having is how to select the column names like "totalhourabsent" and "totalhourpresent" that aren't in the database table but rather in the stored procedure.
Below is my stored procedure:
CREATE PROCEDURE [dbo].[GetAttendanceByHours]
AS
BEGIN
Select *,
ISNULL(NO_HRS_PRESENT,0)*100/ ((ISNULL(NO_HRS_PRESENT,0))+(ISNULL(NO_HRS_ABSNT,0))) PRSNT_PERC,
ISNULL(NO_HRS_ABSNT,0)*100/ ((ISNULL(NO_HRS_PRESENT,0))+(ISNULL(NO_HRS_ABSNT,0))) ABSNT_PERC
from
(
select
REGNO,
FIRSTNAME,
LASTNAME,
MAX(case when status = 'P' THEN CNT end) NO_HRS_PRESENT,
MAX(case WHEN STATUS = 'A' THEN CNT END) NO_HRS_ABSNT
from
(
select
REGNO,FIRSTNAME, LASTNAME,status,
count(status) CNT from AttendanceTable
group by regno,firstname, lastname, status
) A
GROUP BY regno,firstname, lastname
) tmp
END
Vincent Maverick DuranoPosted Apr 26, 2016, 10:44 AM
Benjamin AllenPosted Apr 26, 2016, 10:13 AM
This is really helpful Mr. Vincent but I want to include a "where clause" in the select query so that a user can enter either student regno in a textbox or date(from and to) which also appeared in a textbox when user select calendar date on the web form, so that only record for that specified student or date is displayed on a gridview.
Thanks
Vincent Maverick DuranoPosted Apr 26, 2016, 7:37 AM
Manas MohapatraPosted Apr 26, 2016, 1:11 AM
ISNULL(NO_HRS_PRESENT,0)*100/ ((ISNULL(NO_HRS_PRESENT,0))+(ISNULL(NO_HRS_ABSNT,0))) PRSNT_PERC,
ISNULL(NO_HRS_ABSNT,0)*100/ ((ISNULL(NO_HRS_PRESENT,0))+(ISNULL(NO_HRS_ABSNT,0))) ABSNT_PERC
Benjamin AllenPosted Apr 26, 2016, 1:01 AM
Manas the values of the columns comes from a column named status("P" for present and "A" for absent) in my database table. The COUNT of "P" is where I got the totalpresent column and from there I calculated the percentage as seen in the stored procedure.
Thanks
Benjamin AllenPosted Apr 26, 2016, 12:55 AM
Thanks Amit but sorry I don't understand it very well. You mean I should create a new stored procedure that the one I had already created? It will be better I you can give me one short example.
Thanks once more
Manas MohapatraPosted Apr 26, 2016, 12:50 AM
Amit Kumar SinghPosted Apr 26, 2016, 12:42 AM
Benjamin AllenPosted Apr 25, 2016, 8:18 PM
Thanks Vincent for the reply. Selecting them from the stored procedure isn't what is giving me problem but select those required columns from the already created stored procedure under a "button" event is what is giving problem as the columns aren't on the database table.
Or let me put is this way, I want to execute the stored procedure from my code behind under a button event
Vincent Maverick DuranoPosted Apr 25, 2016, 2:56 PM