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 DuranoRank #238 · 10.3K reputationPosted Apr 26, 2016, 6:44 AM EDT
Vincent Maverick DuranoRank #238 · 10.3K reputationPosted Apr 25, 2016, 10:56 AM EDT
Benjamin Allen31 reputationPosted Apr 25, 2016, 4:18 PM EDT
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
Amit Kumar SinghRank #562 · 4.3K reputationPosted Apr 25, 2016, 8:42 PM EDT
Manas MohapatraRank #182 · 13.2K reputationPosted Apr 25, 2016, 8:50 PM EDT
Benjamin Allen31 reputationPosted Apr 25, 2016, 8:55 PM EDT
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
Benjamin Allen31 reputationPosted Apr 25, 2016, 9:01 PM EDT
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
Manas MohapatraRank #182 · 13.2K reputationPosted Apr 25, 2016, 9:11 PM EDT
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
Vincent Maverick DuranoRank #238 · 10.3K reputationPosted Apr 26, 2016, 3:37 AM EDT
Benjamin Allen31 reputationPosted Apr 26, 2016, 6:13 AM EDT
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